Skip to content

Commit 24afc39

Browse files
authored
Add finally context var test case for kubeflow#1035 (kubeflow#1036)
1 parent 2900f9e commit 24afc39

File tree

3 files changed

+356
-0
lines changed

3 files changed

+356
-0
lines changed

sdk/python/tests/compiler/compiler_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def test_condition_workflow(self):
7878
from .testdata.condition import flipcoin
7979
self._test_pipeline_workflow(flipcoin, 'condition.yaml', skip_noninlined=True)
8080

81+
def test_finally_context_var_workflow(self):
82+
"""
83+
Test compiling a exit handler workflow with Tekton context variable
84+
"""
85+
from .testdata.finally_context_var import any_sequencer_in_finally
86+
self._test_pipeline_workflow(any_sequencer_in_finally, 'finally_context_var.yaml', skip_noninlined=True)
87+
8188
def test_condition_custom_task_workflow(self):
8289
"""
8390
Test compiling a conditional workflow with custom task
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Copyright 2022 kubeflow.org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
from kfp import dsl
17+
from kfp.components import load_component_from_text
18+
from kfp_tekton.compiler import TektonCompiler
19+
from kfp_tekton.tekton import AddOnGroup, AnySequencer
20+
21+
22+
class ExitHandler(AddOnGroup):
23+
"""A custom OpsGroup which maps to a custom task"""
24+
def __init__(self):
25+
labels = {
26+
'pipelines.kubeflow.org/cache_enabled': 'false',
27+
}
28+
29+
super().__init__(
30+
kind='Exception',
31+
api_version='custom.tekton.dev/v1alpha1',
32+
params={},
33+
is_finally=True,
34+
labels=labels,
35+
annotations={},
36+
)
37+
38+
def __enter__(self):
39+
return super().__enter__()
40+
41+
42+
def PrintOp(name: str, msg: str = None):
43+
if msg is None:
44+
msg = name
45+
print_op = load_component_from_text(
46+
"""
47+
name: %s
48+
inputs:
49+
- {name: input_text, type: String, description: 'Represents an input parameter.'}
50+
outputs:
51+
- {name: output_value, type: String, description: 'Represents an output paramter.'}
52+
implementation:
53+
container:
54+
image: alpine:3.6
55+
command:
56+
- sh
57+
- -c
58+
- |
59+
set -e
60+
echo $0 > $1
61+
- {inputValue: input_text}
62+
- {outputPath: output_value}
63+
""" % name
64+
)
65+
return print_op(msg)
66+
67+
68+
@dsl.pipeline("any-sequencer in finally")
69+
def any_sequencer_in_finally():
70+
print00 = PrintOp("print-00")
71+
print01 = PrintOp("print-01")
72+
AnySequencer([print00, print01])
73+
74+
with ExitHandler():
75+
print10 = PrintOp("print-10")
76+
print11 = PrintOp("print-11")
77+
AnySequencer([print10, print11])
78+
79+
80+
if __name__ == '__main__':
81+
TektonCompiler().compile(any_sequencer_in_finally, __file__.replace('.py', '.yaml'))
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
# Copyright 2021 kubeflow.org
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: tekton.dev/v1beta1
16+
kind: PipelineRun
17+
metadata:
18+
name: any-sequencer-in-finally
19+
annotations:
20+
tekton.dev/output_artifacts: '{"none": [{"key": "artifacts/$PIPELINERUN/none/None.tgz",
21+
"name": "none-None", "path": "/tmp/outputs/None/data"}], "none-2": [{"key":
22+
"artifacts/$PIPELINERUN/none-2/None.tgz", "name": "none-2-None", "path": "/tmp/outputs/None/data"}],
23+
"print-00": [{"key": "artifacts/$PIPELINERUN/print-00/output_value.tgz", "name":
24+
"print-00-output_value", "path": "/tmp/outputs/output_value/data"}], "print-01":
25+
[{"key": "artifacts/$PIPELINERUN/print-01/output_value.tgz", "name": "print-01-output_value",
26+
"path": "/tmp/outputs/output_value/data"}], "print-10": [{"key": "artifacts/$PIPELINERUN/print-10/output_value.tgz",
27+
"name": "print-10-output_value", "path": "/tmp/outputs/output_value/data"}],
28+
"print-11": [{"key": "artifacts/$PIPELINERUN/print-11/output_value.tgz", "name":
29+
"print-11-output_value", "path": "/tmp/outputs/output_value/data"}]}'
30+
tekton.dev/input_artifacts: '{}'
31+
tekton.dev/artifact_bucket: mlpipeline
32+
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
33+
tekton.dev/artifact_endpoint_scheme: http://
34+
tekton.dev/artifact_items: '{"none": [["None", "$(results.None.path)"]], "none-2":
35+
[["None", "$(results.None.path)"]], "print-00": [["output_value", "$(results.output-value.path)"]],
36+
"print-01": [["output_value", "$(results.output-value.path)"]], "print-10":
37+
[["output_value", "$(results.output-value.path)"]], "print-11": [["output_value",
38+
"$(results.output-value.path)"]]}'
39+
sidecar.istio.io/inject: "false"
40+
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/$ORIG_PR_NAME/$TASKRUN_NAME/$TASK_PARAM_NAME
41+
pipelines.kubeflow.org/pipeline_spec: '{"name": "any-sequencer in finally"}'
42+
labels:
43+
pipelines.kubeflow.org/pipelinename: ''
44+
pipelines.kubeflow.org/generation: ''
45+
spec:
46+
pipelineSpec:
47+
tasks:
48+
- name: print-00
49+
taskSpec:
50+
steps:
51+
- name: main
52+
command:
53+
- sh
54+
- -c
55+
- |
56+
set -e
57+
echo $0 > $1
58+
- print-00
59+
- $(results.output-value.path)
60+
image: alpine:3.6
61+
results:
62+
- name: output-value
63+
type: string
64+
description: /tmp/outputs/output_value/data
65+
metadata:
66+
labels:
67+
pipelines.kubeflow.org/cache_enabled: "true"
68+
annotations:
69+
pipelines.kubeflow.org/component_spec_digest: '{"name": "print-00", "outputs":
70+
[{"description": "Represents an output paramter.", "name": "output_value",
71+
"type": "String"}], "version": "print-00@sha256=7c633686b0b637cfba6cba8c9b4e871cf172395432360d6aaa2d89623fb336b3"}'
72+
tekton.dev/template: ''
73+
timeout: 525600m
74+
- name: print-01
75+
taskSpec:
76+
steps:
77+
- name: main
78+
command:
79+
- sh
80+
- -c
81+
- |
82+
set -e
83+
echo $0 > $1
84+
- print-01
85+
- $(results.output-value.path)
86+
image: alpine:3.6
87+
results:
88+
- name: output-value
89+
type: string
90+
description: /tmp/outputs/output_value/data
91+
metadata:
92+
labels:
93+
pipelines.kubeflow.org/cache_enabled: "true"
94+
annotations:
95+
pipelines.kubeflow.org/component_spec_digest: '{"name": "print-01", "outputs":
96+
[{"description": "Represents an output paramter.", "name": "output_value",
97+
"type": "String"}], "version": "print-01@sha256=d511ac628d43cc5b393fbebd10be93662b30117f1413b84afd4e7b2e5ff5ed33"}'
98+
tekton.dev/template: ''
99+
timeout: 525600m
100+
- name: none
101+
taskSpec:
102+
steps:
103+
- name: main
104+
args:
105+
- --namespace
106+
- $(params.pipelineRun-namespace)
107+
- --prName
108+
- $(params.pipelineRun-name)
109+
- --taskList
110+
- print-00,print-01
111+
command:
112+
- any-task
113+
image: dspipelines/any-sequencer:latest
114+
- image: busybox
115+
name: copy-results
116+
command:
117+
- sh
118+
- -ec
119+
- |
120+
set -exo pipefail
121+
cp /tmp/outputs/None/data $(results.None.path);
122+
results:
123+
- name: None
124+
type: string
125+
description: /tmp/outputs/None/data
126+
stepTemplate:
127+
volumeMounts:
128+
- name: none
129+
mountPath: /tmp/outputs/None
130+
volumes:
131+
- name: none
132+
emptyDir: {}
133+
metadata:
134+
labels:
135+
pipelines.kubeflow.org/cache_enabled: "true"
136+
annotations:
137+
pipelines.kubeflow.org/component_spec_digest: '{"name": "None", "outputs":
138+
[{"description": "The output file to create the status", "name": "None"}],
139+
"version": "None@sha256=d85996d2400bd94ea45204590fcba9374edf952e060744ff0c5a5102f1318d7f"}'
140+
tekton.dev/template: ''
141+
params:
142+
- name: pipelineRun-name
143+
- name: pipelineRun-namespace
144+
timeout: 525600m
145+
params:
146+
- name: pipelineRun-name
147+
value: $(context.pipelineRun.name)
148+
- name: pipelineRun-namespace
149+
value: $(context.pipelineRun.namespace)
150+
finally:
151+
- name: any-sequencer-in-finally-addon-group-1
152+
taskSpec:
153+
apiVersion: custom.tekton.dev/v1alpha1
154+
kind: Exception
155+
spec:
156+
pipelineSpec:
157+
params: []
158+
tasks:
159+
- name: print-10
160+
taskSpec:
161+
steps:
162+
- name: main
163+
command:
164+
- sh
165+
- -c
166+
- |
167+
set -e
168+
echo $0 > $1
169+
- print-10
170+
- $(results.output-value.path)
171+
image: alpine:3.6
172+
results:
173+
- name: output-value
174+
type: string
175+
description: /tmp/outputs/output_value/data
176+
metadata:
177+
labels:
178+
pipelines.kubeflow.org/cache_enabled: "true"
179+
annotations:
180+
pipelines.kubeflow.org/component_spec_digest: '{"name": "print-10",
181+
"outputs": [{"description": "Represents an output paramter.",
182+
"name": "output_value", "type": "String"}], "version": "print-10@sha256=ea7fa8edfd92cf64a15f8464292143a4e0d5f34898368bfd63618884decf3be1"}'
183+
tekton.dev/template: ''
184+
timeout: 525600m
185+
- name: print-11
186+
taskSpec:
187+
steps:
188+
- name: main
189+
command:
190+
- sh
191+
- -c
192+
- |
193+
set -e
194+
echo $0 > $1
195+
- print-11
196+
- $(results.output-value.path)
197+
image: alpine:3.6
198+
results:
199+
- name: output-value
200+
type: string
201+
description: /tmp/outputs/output_value/data
202+
metadata:
203+
labels:
204+
pipelines.kubeflow.org/cache_enabled: "true"
205+
annotations:
206+
pipelines.kubeflow.org/component_spec_digest: '{"name": "print-11",
207+
"outputs": [{"description": "Represents an output paramter.",
208+
"name": "output_value", "type": "String"}], "version": "print-11@sha256=3b423bb0ced0bc21fb9157ce814a38c94d3e72718a33cfa8b4ef4f75abe725bd"}'
209+
tekton.dev/template: ''
210+
timeout: 525600m
211+
- name: none-2
212+
taskSpec:
213+
steps:
214+
- name: main
215+
args:
216+
- --namespace
217+
- $(params.pipelineRun-namespace)
218+
- --prName
219+
- $(params.pipelineRun-name)
220+
- --taskList
221+
- print-10,print-11
222+
command:
223+
- any-task
224+
image: dspipelines/any-sequencer:latest
225+
- image: busybox
226+
name: copy-results
227+
command:
228+
- sh
229+
- -ec
230+
- |
231+
set -exo pipefail
232+
cp /tmp/outputs/None/data $(results.None.path);
233+
results:
234+
- name: None
235+
type: string
236+
description: /tmp/outputs/None/data
237+
stepTemplate:
238+
volumeMounts:
239+
- name: none
240+
mountPath: /tmp/outputs/None
241+
volumes:
242+
- name: none
243+
emptyDir: {}
244+
metadata:
245+
labels:
246+
pipelines.kubeflow.org/cache_enabled: "true"
247+
annotations:
248+
pipelines.kubeflow.org/component_spec_digest: '{"name": "None",
249+
"outputs": [{"description": "The output file to create the status",
250+
"name": "None"}], "version": "None@sha256=aa59b9bee1939a20a127f07c0be2c186967560086207bc68a8d0401e03b63dcd"}'
251+
tekton.dev/template: ''
252+
params:
253+
- name: pipelineRun-name
254+
type: string
255+
- name: pipelineRun-namespace
256+
type: string
257+
timeout: 525600m
258+
params:
259+
- name: pipelineRun-name
260+
value: $(context.pipelineRun.name)
261+
- name: pipelineRun-namespace
262+
value: $(context.pipelineRun.namespace)
263+
metadata:
264+
labels:
265+
pipelines.kubeflow.org/cache_enabled: "false"
266+
timeouts:
267+
pipeline: 1051200m
268+
tasks: 525600m

0 commit comments

Comments
 (0)