Skip to content

Commit

Permalink
Enhance unit tests with local Tekton pipeline spec validation (kubefl…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomcli authored Aug 5, 2021
1 parent 982ad55 commit 58b01f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/kfp-tekton-unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: KFP Tekton Unit Tests
on:
push:
branches: [master]

# Run tests for any PRs.
pull_request:

Expand All @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "=================================================================="
Expand Down
13 changes: 10 additions & 3 deletions tekton-catalog/pipeline-loops/cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 58b01f9

Please sign in to comment.