Skip to content

Commit

Permalink
Enable pipelineparam for container env (kubeflow#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomcli committed Jan 19, 2022
1 parent 6d2682d commit 1f75071
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/python/kfp_tekton/compiler/_k8s_helper.py
Expand Up @@ -192,6 +192,8 @@ def sanitize_k8s_object(k8s_obj, type=None):
for sub_obj in k8s_obj)
elif isinstance(k8s_obj, (datetime, date)):
return k8s_obj
elif isinstance(k8s_obj, dsl.PipelineParam):
return k8s_obj

if isinstance(k8s_obj, dict):
return k8s_obj
Expand Down
7 changes: 7 additions & 0 deletions sdk/python/tests/compiler/compiler_tests.py
Expand Up @@ -387,6 +387,13 @@ def test_pipelineparams_workflow(self):
from .testdata.pipelineparams import pipelineparams_pipeline
self._test_pipeline_workflow(pipelineparams_pipeline, 'pipelineparams.yaml', skip_noninlined=True)

def test_pipelineparam_env_workflow(self):
"""
Test compiling a pipelineparams workflow.
"""
from .testdata.pipelineparam_env import echo_pipeline
self._test_pipeline_workflow(echo_pipeline, 'pipelineparam_env.yaml', skip_noninlined=True)

def test_retry_workflow(self):
"""
Test compiling a retry task in workflow.
Expand Down
41 changes: 41 additions & 0 deletions sdk/python/tests/compiler/testdata/pipelineparam_env.py
@@ -0,0 +1,41 @@
# Copyright 2022 kubeflow.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from kubernetes.client.models import V1EnvVar
from kfp import dsl


def echo_op(port_number):
return dsl.ContainerOp(
name='echo',
image='busybox',
command=['sh', '-c'],
arguments=['echo "Got scheduled"']
).container.add_env_variable(V1EnvVar(name='PORT', value=port_number))


@dsl.pipeline(
name='echo',
description='echo pipeline'
)
def echo_pipeline(
port_number=80
):
echo = echo_op(port_number)


if __name__ == '__main__':
from kfp_tekton.compiler import TektonCompiler
TektonCompiler().compile(echo_pipeline, 'echo_pipeline.yaml')
65 changes: 65 additions & 0 deletions sdk/python/tests/compiler/testdata/pipelineparam_env.yaml
@@ -0,0 +1,65 @@
# Copyright 2021 kubeflow.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: echo
annotations:
tekton.dev/output_artifacts: '{}'
tekton.dev/input_artifacts: '{}'
tekton.dev/artifact_bucket: mlpipeline
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
tekton.dev/artifact_endpoint_scheme: http://
tekton.dev/artifact_items: '{"echo": []}'
sidecar.istio.io/inject: "false"
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/$ORIG_PR_NAME/$TASKRUN_NAME/$TASK_PARAM_NAME
pipelines.kubeflow.org/pipeline_spec: '{"description": "echo pipeline", "inputs":
[{"default": "80", "name": "port_number", "optional": true}], "name": "echo"}'
spec:
params:
- name: port_number
value: '80'
pipelineSpec:
params:
- name: port_number
default: '80'
tasks:
- name: echo
params:
- name: port_number
value: $(params.port_number)
taskSpec:
steps:
- name: main
args:
- echo "Got scheduled"
command:
- sh
- -c
env:
- name: PORT
value: $(inputs.params.port_number)
image: busybox
params:
- name: port_number
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
tekton.dev/template: ''
timeout: 525600m
timeout: 525600m

0 comments on commit 1f75071

Please sign in to comment.