[kfp sdk] Added examples for ArtifactLocation, ResourceOp, VolumeOp, and Sidecar. (#1338)

* Added examples for ArtifactLocation, ResourceOp, VolumeOp, and Sidecar.

* remove resourceop and volumeop examples

* Sample for pipeline level artifact location only
This commit is contained in:
Eterna2 2019-05-17 09:29:29 +08:00 committed by Kubernetes Prow Robot
parent 78bfdaffa9
commit d821e79622
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,42 @@
#!/usr/bin/env python3
# Copyright 2019 Google LLC
#
# 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 kfp import dsl
from kubernetes.client import V1SecretKeySelector
@dsl.pipeline(
name="custom_artifact_location_pipeline",
description="""A pipeline to demonstrate how to configure the artifact
location for all the ops in the pipeline.""",
)
def custom_artifact_location(
tag: str, namespace: str = "kubeflow", bucket: str = "somebucket"
):
# configures artifact location
pipeline_artifact_location = dsl.ArtifactLocation.s3(
bucket=bucket,
endpoint="minio-service.%s:9000" % namespace, # parameterize minio-service endpoint
insecure=True,
access_key_secret=V1SecretKeySelector(name="minio", key="accesskey"),
secret_key_secret={"name": "minio", "key": "secretkey"}, # accepts dict also
)
# set pipeline level artifact location
dsl.get_pipeline_conf().set_artifact_location(pipeline_artifact_location)
# artifacts in this op are stored to endpoint `minio-service.<namespace>:9000`
op = dsl.ContainerOp(name="foo", image="busybox:%s" % tag)

49
samples/basic/sidecar.py Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env python3
# Copyright 2019 Google LLC
#
# 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
@dsl.pipeline(
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):
# sidecar with sevice that reply "hello world" to any GET request
echo = dsl.Sidecar(
name="echo",
image="hashicorp/http-echo:latest",
args=['-text="hello world"'],
)
# container op with sidecar
op1 = dsl.ContainerOp(
name="download",
image="busybox:latest",
command=["sh", "-c"],
arguments=[
"sleep %s; wget localhost:5678 -O /tmp/results.txt" % sleep_ms
], # sleep for X sec and call the sidecar and save results to output
sidecars=[echo],
file_outputs={"downloaded": "/tmp/results.txt"},
)
op2 = dsl.ContainerOp(
name="echo",
image="library/bash",
command=["sh", "-c"],
arguments=["echo %s" % op1.output], # print out content of op1 output
)