Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sidecars #42

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sdk/python/kfp_tekton/compiler/_op_to_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ def _op_to_template(op: BaseOp):

# sidecars
if processed_op.sidecars:
raise NotImplementedError("'sidecars' are not (yet) implemented")
template['sidecars'] = processed_op.sidecars
template['spec']['sidecars'] = processed_op.sidecars

# volumes
if processed_op.volumes:
Expand Down
13 changes: 7 additions & 6 deletions sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import kfp.dsl as dsl
import json
import os
import shutil
import sys
import tarfile
import tempfile
import unittest
import yaml
import zipfile

from kfp_tekton import compiler

from . import testdata

# after code changes that change the YAML output, temporarily set this flag to True
# in order to generate new "golden" YAML files
Expand All @@ -48,6 +42,13 @@ def test_parallel_join_workflow(self):
from .testdata.parallel_join import download_and_join
self._test_pipeline_workflow(download_and_join, 'parallel_join.yaml')

def test_sidecar_workflow(self):
"""
Test compiling a sidecar workflow.
"""
from .testdata.sidecar import sidecar_pipeline
self._test_pipeline_workflow(sidecar_pipeline, 'sidecar.yaml')

def test_volume_workflow(self):
"""
Test compiling a Waston ML workflow.
Expand Down
39 changes: 39 additions & 0 deletions sdk/python/tests/compiler/testdata/sidecar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2020 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.

import kfp.dsl as dsl
from kubernetes import client as k8s_client


@dsl.pipeline(name='Sidecar', description='A pipeline with sidecars.')
def sidecar_pipeline():

echo = dsl.Sidecar(
name='echo',
image='hashicorp/http-echo',
args=['-text="hello world"'])

op1 = dsl.ContainerOp(
name='download',
image='busybox',
command=['sh', '-c'],
arguments=['sleep 10; wget localhost:5678 -O /tmp/results.txt'],
sidecars=[echo],
file_outputs={'downloaded': '/tmp/results.txt'})

op2 = dsl.ContainerOp(
name='echo',
image='library/bash',
command=['sh', '-c'],
arguments=['echo %s' % op1.output])
72 changes: 72 additions & 0 deletions sdk/python/tests/compiler/testdata/sidecar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2020 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
fenglixa marked this conversation as resolved.
Show resolved Hide resolved
kind: Task
metadata:
name: download
spec:
results:
- description: /tmp/results.txt
name: downloaded
sidecars:
- args:
- -text="hello world"
image: hashicorp/http-echo
name: echo
steps:
- args:
- sleep 10; wget localhost:5678 -O $(results.downloaded.path)
command:
- sh
- -c
image: busybox
name: download
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: echo
spec:
params:
- name: download-downloaded
steps:
- args:
- echo $(inputs.params.download-downloaded)
command:
- sh
- -c
image: library/bash
name: echo
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with sidecars.",
"name": "Sidecar"}'
name: sidecar
spec:
params: []
tasks:
- name: download
params: []
taskRef:
name: download
- name: echo
params:
- name: download-downloaded
value: $(tasks.download.results.downloaded)
taskRef:
name: echo