Skip to content

Commit

Permalink
feat(sdk): Add pipelineloop validation for testdata yamls. (kubeflow#660
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ScrapCodes authored Jul 8, 2021
1 parent 0ad68be commit 9d79f84
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 52 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ $(VENV)/bin/activate: sdk/python/setup.py
install: venv ## Install the kfp_tekton compiler in a virtual environment
@echo "Run 'source $(VENV)/bin/activate' to activate the virtual environment."

.PHONY: validate_testdata
validate-testdata:
@cd tekton-catalog/pipeline-loops/ && make validate-testdata-python-sdk

.PHONY: unit_test
unit_test: venv ## Run compiler unit tests
unit_test: venv validate-testdata ## 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 Down
4 changes: 2 additions & 2 deletions sdk/python/tests/compiler/testdata/conditions_and_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def produce_number() -> int:


@dsl.pipeline(name='Conditions and loops')
def conditions_and_loops(n='3', threshold='20'):
produce_numbers_task = produce_numbers(n)
def conditions_and_loops(n1='3', threshold='20'):
produce_numbers_task = produce_numbers(n1)
with dsl.ParallelFor(produce_numbers_task.output) as loop_item:
add_numbers_task = add_numbers(loop_item, '10')
print_number_task = print_number(add_numbers_task.output)
Expand Down
14 changes: 7 additions & 7 deletions sdk/python/tests/compiler/testdata/conditions_and_loops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "3", "name": "n",
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "3", "name": "n1",
"optional": true}, {"default": "20", "name": "threshold", "optional": true}],
"name": "Conditions and loops"}'
sidecar.istio.io/inject: 'false'
Expand All @@ -36,21 +36,21 @@ metadata:
name: conditions-and-loops
spec:
params:
- name: n
- name: n1
value: '3'
- name: threshold
value: '20'
pipelineSpec:
params:
- default: '3'
name: n
name: n1
- default: '20'
name: threshold
tasks:
- name: produce-numbers
params:
- name: n
value: $(params.n)
- name: n1
value: $(params.n1)
taskSpec:
metadata:
annotations:
Expand Down Expand Up @@ -81,14 +81,14 @@ spec:
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/pipelinename: ''
params:
- name: n
- name: n1
results:
- description: /tmp/outputs/Output/data
name: output
steps:
- args:
- --n
- $(inputs.params.n)
- $(inputs.params.n1)
- '----output-paths'
- $(results.output.path)
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "3", "name": "n",
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "3", "name": "n1",
"optional": true}, {"default": "20", "name": "threshold", "optional": true}],
"name": "Conditions and loops"}'
sidecar.istio.io/inject: 'false'
Expand All @@ -36,21 +36,21 @@ metadata:
name: conditions-and-loops
spec:
params:
- name: n
- name: n1
value: '3'
- name: threshold
value: '20'
pipelineSpec:
params:
- default: '3'
name: n
name: n1
- default: '20'
name: threshold
tasks:
- name: produce-numbers
params:
- name: n
value: $(params.n)
- name: n1
value: $(params.n1)
taskSpec:
metadata:
annotations:
Expand Down Expand Up @@ -81,14 +81,14 @@ spec:
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/pipelinename: ''
params:
- name: n
- name: n1
results:
- description: /tmp/outputs/Output/data
name: output
steps:
- args:
- --n
- $(inputs.params.n)
- $(inputs.params.n1)
- '----output-paths'
- $(results.output.path)
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def produce_number() -> int:


@dsl.pipeline(name='Conditions with global params')
def conditions_with_global_params(n='5', threshold='10', lower_bound='15'):
add_numbers_task = add_numbers(n, lower_bound)
def conditions_with_global_params(n1='5', threshold='10', lower_bound='15'):
add_numbers_task = add_numbers(n1, lower_bound)
print_number_task = print_number(add_numbers_task.output)
with dsl.Condition(print_number_task.output > threshold):
notify_success()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "5", "name": "n",
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "5", "name": "n1",
"optional": true}, {"default": "10", "name": "threshold", "optional": true},
{"default": "15", "name": "lower_bound", "optional": true}], "name": "Conditions
with global params"}'
Expand All @@ -35,7 +35,7 @@ metadata:
name: conditions-with-global-params
spec:
params:
- name: n
- name: n1
value: '5'
- name: threshold
value: '10'
Expand All @@ -44,7 +44,7 @@ spec:
pipelineSpec:
params:
- default: '5'
name: n
name: n1
- default: '10'
name: threshold
- default: '15'
Expand All @@ -54,8 +54,8 @@ spec:
params:
- name: lower_bound
value: $(params.lower_bound)
- name: n
value: $(params.n)
- name: n1
value: $(params.n1)
taskSpec:
metadata:
annotations:
Expand Down Expand Up @@ -86,14 +86,14 @@ spec:
pipelines.kubeflow.org/pipelinename: ''
params:
- name: lower_bound
- name: n
- name: n1
results:
- description: /tmp/outputs/Output/data
name: output
steps:
- args:
- --a
- $(inputs.params.n)
- $(inputs.params.n1)
- --b
- $(inputs.params.lower_bound)
- '----output-paths'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "5", "name": "n",
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "5", "name": "n1",
"optional": true}, {"default": "10", "name": "threshold", "optional": true},
{"default": "15", "name": "lower_bound", "optional": true}], "name": "Conditions
with global params"}'
Expand All @@ -35,7 +35,7 @@ metadata:
name: conditions-with-global-params
spec:
params:
- name: n
- name: n1
value: '5'
- name: threshold
value: '10'
Expand All @@ -44,7 +44,7 @@ spec:
pipelineSpec:
params:
- default: '5'
name: n
name: n1
- default: '10'
name: threshold
- default: '15'
Expand All @@ -54,8 +54,8 @@ spec:
params:
- name: lower_bound
value: $(params.lower_bound)
- name: n
value: $(params.n)
- name: n1
value: $(params.n1)
taskSpec:
metadata:
annotations:
Expand Down Expand Up @@ -86,14 +86,14 @@ spec:
pipelines.kubeflow.org/pipelinename: ''
params:
- name: lower_bound
- name: n
- name: n1
results:
- description: /tmp/outputs/Output/data
name: output
steps:
- args:
- --a
- $(inputs.params.n)
- $(inputs.params.n1)
- --b
- $(inputs.params.lower_bound)
- '----output-paths'
Expand Down
12 changes: 11 additions & 1 deletion tekton-catalog/pipeline-loops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,28 @@ all:
KO = ko
ko: PACKAGE=github.com/google/ko/cmd/ko

apply: $(info apply PipelineLoop controller to the k8s cluster )
apply: $(info apply: Apply PipelineLoop controller to the k8s cluster )
$(KO) apply -f config

test-all: $(info test-all: run unit tests )
go test -v -cover -timeout=${TIMEOUT_TESTS} ./...

.PHONY: init
init:
mkdir -p ${BIN_DIR}

.PHONY: cli
cli: init $(info cli: build validation cli )
go build -o=${BIN_DIR}/pipelineloop-cli ./cmd/cli

.PHONY: validate-testdata-python-sdk
validate-testdata-python-sdk: cli $(info validate-testdata-python-sdk: validate testdata for python SDK )
## works w/o findutils installed, but globbing has a limit
## for x in ../../sdk/python/tests/compiler/testdata/*yaml; do ${BIN_DIR}/pipelineloop-cli -f $$x || true ; done
@find ../../sdk/python/tests/compiler/testdata \
\( -type f -name "*yaml" -not -path "*\test_data\*" -not -name "*component.yaml" \) \
-print0 | xargs -0 -n1 ${BIN_DIR}/pipelineloop-cli -f

local: init
go build -o=${BIN_DIR}/pipelineloop-controller ./cmd/controller
go build -o=${BIN_DIR}/pipelineloop-webhook ./cmd/webhook
Expand Down
Loading

0 comments on commit 9d79f84

Please sign in to comment.