Repository: kubeflow/kfp-tekton (language: python)

Issue:
Verify generated Tekton YAML
/kind feature

**Description:**
After [upgrading to KFP SDK version 0.5.0](#135) we took over some code to:
- verify the variables resolution in the parameters of the generated compiled workflow and 
- lint the generated Tekton YAML (syntax verification)
 
That code is commented out as a guide just to serve as a guide for the appropriate Tekton specific implementation. 

We should implement the method `kfp_tekton.compiler.compiler._validate_workflow` when time permits to catch problems with the Tekton YAML before a pipeline gets deployed.

**Additional information:**
_Originally posted by @ckadner in https://github.com/kubeflow/kfp-tekton/pull/135_



Discussion / hints:
Issue Label Bot is not confident enough to auto-label this issue.
                See [dashboard](https://github.com/marketplace/issue-label-botdata/kubeflow/kfp-tekton) for more details.
                
@afrittoli -- does Tekton have a CLI tool to parse and verify the YAML locally (before deploying it to the cluster)?
@afrittoli -- is there a tool or some programmatic way to verify a given Tekton YAML is valid and compliant with the specified API version?
Currently I apply my compiled Tekton YAML to a Kubernetes cluster with Tekton deployed on it and look for errors. That approach works on a one-by-one basis or in end-to-end test cases but it does not work as part of the compiler code.
There are some validation used [here](https://github.com/tektoncd/pipeline/blob/858305d73b806583f9592dd166fdd360f5844423/pkg/apis/pipeline/v1beta1/pipeline_validation.go) for tekton pipelines. I have tried to check for any CLI validation but can't find any. @ckadner 
I could start to look in to the pipeline validation, will try to do it in steps and see how the validation is done in the tekton repo. 
@NikeNano -- thanks for helping out on this task. I was really hoping for a CLI that allows to validate Tekton pipelines since I do not want us to duplicate (or refashion) Golang code from Tekton in this repo. This would inevitably go out of sync.

Maybe we could advocate for (or contribute) a small executable wrapper around the Tekton [`pipeline_validation`](https://github.com/tektoncd/pipeline/blob/master/pkg/apis/pipeline/v1beta1/pipeline_validation.go) and include the validation for `PipelineRun`, `Task`, `Condition`, ...
Good point!
 
> Maybe we could advocate for (or contribute) a small executable wrapper around the Tekton [`pipeline_validation`](https://github.com/tektoncd/pipeline/blob/master/pkg/apis/pipeline/v1beta1/pipeline_validation.go) and include the validation for `PipelineRun`, `Task`, `Condition`, ...

I will look into making it as an contribution to tekton that we can reuse! 
Based upon the discussion [here](https://github.com/tektoncd/cli/issues/999) it currently is not suiting for the Tekton cli tool. But I guess we could still pursue a small executable to validate the the resources you mention @ckadner 
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@ckadner I was just looking for this as well. What a coincidence that you had already opened an issue for this feature, and it was the first link I clicked on 😀. It's pretty annoying to deploy a pipeline just to figure out whether the yaml is valid or not 😢.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Fix patch:
diff --git a/Makefile b/Makefile
index 8b1f381623..1ebea7e388 100644
--- a/Makefile
+++ b/Makefile
@@ -45,9 +45,10 @@ install: venv ## Install the kfp_tekton compiler in a virtual environment
 .PHONY: validate_testdata
 validate-testdata:
 	@cd tekton-catalog/pipeline-loops/ && make validate-testdata-python-sdk
+	@echo "$@: OK"
 
 .PHONY: unit_test
-unit_test: venv validate-testdata ## Run compiler unit tests
+unit_test: venv ## Run compiler unit tests
 	@echo "=================================================================="
 	@echo "Optional environment variables to configure $@, examples:"
 	@sed -n -e 's/# *\(make $@ .*\)/  \1/p' sdk/python/tests/compiler/compiler_tests.py
@@ -56,6 +57,9 @@ unit_test: venv validate-testdata ## Run compiler unit tests
 	@sdk/python/tests/run_tests.sh
 	@echo "$@: OK"
 
+.PHONY: ci_unit_test
+ci_unit_test: unit_test validate-testdata
+
 .PHONY: e2e_test
 e2e_test: venv ## Run compiler end-to-end tests (requires kubectl and tkn CLI)
 	@echo "=================================================================="
diff --git a/tekton-catalog/pipeline-loops/cmd/cli/main.go b/tekton-catalog/pipeline-loops/cmd/cli/main.go
index 5b3fee73a4..2ba74e2fe8 100644
--- a/tekton-catalog/pipeline-loops/cmd/cli/main.go
+++ b/tekton-catalog/pipeline-loops/cmd/cli/main.go
@@ -129,9 +129,7 @@ func validatePipeline(bytes []byte) error {
 
 func validatePipelineSpec(p *v1beta1.PipelineSpec, name string) error {
 	errs := []string{}
-	// We do not need to validate PipelineRun because it is validated by tekton admission webhook
-	// And pipelineTask.TaskRef is also validated by tekton.
-	// Here we only need to validate those embedded spec, whose kind is pipelineLoop.
+	// Here we validate those embedded spec, whose kind is pipelineLoop.
 	if p.Tasks != nil {
 		for _, task := range p.Tasks {
 			if task.TaskSpec != nil && task.TaskSpec.Kind == pipelineloop.PipelineLoopControllerName {
@@ -146,6 +144,15 @@ func validatePipelineSpec(p *v1beta1.PipelineSpec, name string) error {
 		e := strings.Join(errs, "\n")
 		return fmt.Errorf("Validation errors found in pipeline %s\n %s", name, e)
 	}
+
+	// Validate the Tekton pipelineSpec
+	ctx := context.Background()
+	ctx = pipelinelooprun.EnableCustomTaskFeatureFlag(ctx)
+	p.SetDefaults(ctx)
+	errors := p.Validate(ctx)
+	if errors != nil {
+		return errors
+	}
 	return nil
 }
 


Test patch:
diff --git a/.github/workflows/kfp-tekton-unittests.yml b/.github/workflows/kfp-tekton-unittests.yml
index c08549e0ba..d9ee8b54e1 100644
--- a/.github/workflows/kfp-tekton-unittests.yml
+++ b/.github/workflows/kfp-tekton-unittests.yml
@@ -3,7 +3,7 @@ name: KFP Tekton Unit Tests
 on:
   push:
     branches: [master]
-    
+
   # Run tests for any PRs.
   pull_request:
 
@@ -25,7 +25,7 @@ jobs:
       - name: Install dependencies
         run: python -m pip install -e sdk/python
       - name: Unit Tests
-        run: VENV=$VIRTUAL_ENV make unit_test
+        run: VENV=$VIRTUAL_ENV make ci_unit_test
   progress-report:
     runs-on: ubuntu-latest
     steps: