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 more core samples in the sample test #2030

Merged
merged 8 commits into from
Sep 6, 2019
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
22 changes: 10 additions & 12 deletions samples/core/pipeline_transformers/pipeline_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,26 @@
import kfp
from kfp import dsl


def random_failure_op(exit_codes):
"""A component that fails randomly."""
def print_op(msg):
"""Print a message."""
return dsl.ContainerOp(
name='random_failure',
image='python:alpine3.6',
command=['python', '-c'],
arguments=['import random; import sys; exit_code = random.choice(sys.argv[1].split(",")); print(exit_code); sys.exit(exit_code)', exit_codes]
name='Print',
image='alpine:3.6',
command=['echo', msg],
)

def add_retry(op):
op.set_retry(5)
def add_annotation(op):
op.add_pod_annotation(name='hobby', value='football')
return op

@dsl.pipeline(
name='Retry random failures',
description='The pipeline includes two steps which fail randomly. It shows how to use ContainerOp(...).set_retry(...).'
)
def retry_sample_pipeline():
op1 = random_failure_op('0,1,2,3')
op2 = random_failure_op('0,1')
dsl.get_pipeline_conf().add_op_transformer(add_retry)
op1 = print_op('hey, what are you up to?')
op2 = print_op('train my model.')
dsl.get_pipeline_conf().add_op_transformer(add_annotation)

if __name__ == '__main__':
kfp.compiler.Compiler().compile(retry_sample_pipeline, __file__ + '.zip')
4 changes: 2 additions & 2 deletions samples/core/sidecar/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
name="pipeline_with_sidecar",
description="A pipeline that demonstrates how to add a sidecar to an operation."
)
def pipeline_with_sidecar(sleep_ms: int = 10):
def pipeline_with_sidecar(sleep_sec: int = 30):

# sidecar with sevice that reply "hello world" to any GET request
echo = dsl.Sidecar(
Expand All @@ -35,7 +35,7 @@ def pipeline_with_sidecar(sleep_ms: int = 10):
image="busybox:latest",
command=["sh", "-c"],
arguments=[
"sleep %s; wget localhost:5678 -O /tmp/results.txt" % sleep_ms
"sleep %s; wget localhost:5678 -O /tmp/results.txt" % sleep_sec
], # sleep for X sec and call the sidecar and save results to output
sidecars=[echo],
file_outputs={"downloaded": "/tmp/results.txt"},
Expand Down
3 changes: 3 additions & 0 deletions test/sample_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ spec:
- xgboost_training_cm
- lightweight_component
- dsl_static_type_checking
- pipeline_transformers
- secret
- sidecar
# Build and push image
- name: build-image-by-dockerfile
inputs:
Expand Down