forked from opendatahub-io/data-science-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add more k8s resource support * add test main functions as requested * add description on why we need pipelinerun
- Loading branch information
Showing
10 changed files
with
352 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 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. | ||
|
||
from kubernetes.client import V1Affinity, V1NodeSelector, V1NodeSelectorRequirement, V1NodeSelectorTerm, V1NodeAffinity | ||
from kfp.dsl import ContainerOp | ||
from kfp import dsl | ||
|
||
|
||
def some_op(): | ||
return dsl.ContainerOp( | ||
name='sleep', | ||
image='busybox', | ||
command=['sleep 1'], | ||
) | ||
|
||
@dsl.pipeline( | ||
name='affinity', | ||
description='A pipeline with affinity' | ||
) | ||
def affinity_pipeline( | ||
): | ||
"""A pipeline with affinity""" | ||
affinity = V1Affinity( | ||
node_affinity=V1NodeAffinity( | ||
required_during_scheduling_ignored_during_execution=V1NodeSelector( | ||
node_selector_terms=[V1NodeSelectorTerm( | ||
match_expressions=[V1NodeSelectorRequirement( | ||
key='beta.kubernetes.io/instance-type', operator='In', values=['p2.xlarge'])])]))) | ||
some_op().add_affinity(affinity) | ||
|
||
if __name__ == '__main__': | ||
# don't use top-level import of TektonCompiler to prevent monkey-patching KFP compiler when using KFP's dsl-compile | ||
from kfp_tekton.compiler import TektonCompiler | ||
TektonCompiler().compile(affinity_pipeline, __file__.replace('.py', '.yaml'), generate_pipelinerun=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 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 | ||
kind: Task | ||
metadata: | ||
name: sleep | ||
spec: | ||
steps: | ||
- command: | ||
- sleep 1 | ||
image: busybox | ||
name: sleep | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
annotations: | ||
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with affinity", | ||
"name": "affinity"}' | ||
name: affinity | ||
spec: | ||
params: [] | ||
tasks: | ||
- name: sleep | ||
params: [] | ||
taskRef: | ||
name: sleep | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: affinity-run | ||
spec: | ||
params: [] | ||
pipelineRef: | ||
name: affinity | ||
podtemplate: | ||
affinity: | ||
nodeAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
nodeSelectorTerms: | ||
- matchExpressions: | ||
- key: beta.kubernetes.io/instance-type | ||
operator: In | ||
values: | ||
- p2.xlarge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 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. | ||
|
||
from kfp.dsl import ContainerOp | ||
from kfp import dsl | ||
|
||
|
||
def some_op(): | ||
return dsl.ContainerOp( | ||
name='sleep', | ||
image='busybox', | ||
command=['sleep 1'], | ||
) | ||
|
||
@dsl.pipeline( | ||
name='node_selector', | ||
description='A pipeline with Node Selector' | ||
) | ||
def node_selector_pipeline( | ||
): | ||
"""A pipeline with Node Selector""" | ||
some_op().add_node_selector_constraint('accelerator', 'nvidia-tesla-k80') | ||
|
||
if __name__ == '__main__': | ||
# don't use top-level import of TektonCompiler to prevent monkey-patching KFP compiler when using KFP's dsl-compile | ||
from kfp_tekton.compiler import TektonCompiler | ||
TektonCompiler().compile(node_selector_pipeline, __file__.replace('.py', '.yaml'), generate_pipelinerun=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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 | ||
kind: Task | ||
metadata: | ||
name: sleep | ||
spec: | ||
steps: | ||
- command: | ||
- sleep 1 | ||
image: busybox | ||
name: sleep | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
annotations: | ||
pipelines.kubeflow.org/pipeline_spec: '{"description": "A pipeline with Node Selector", | ||
"name": "node_selector"}' | ||
name: node-selector | ||
spec: | ||
params: [] | ||
tasks: | ||
- name: sleep | ||
params: [] | ||
taskRef: | ||
name: sleep | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: node-selector-run | ||
spec: | ||
params: [] | ||
pipelineRef: | ||
name: node-selector | ||
podtemplate: | ||
nodeSelector: | ||
accelerator: nvidia-tesla-k80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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. | ||
|
||
from kubernetes.client import V1Toleration | ||
from kfp.dsl import ContainerOp | ||
from kfp import dsl | ||
|
||
@dsl.pipeline( | ||
name='tolerations', | ||
description='A pipeline with tolerations' | ||
) | ||
def tolerations( | ||
): | ||
"""A pipeline with tolerations""" | ||
op1 = dsl.ContainerOp( | ||
name='download', | ||
image='busybox', | ||
command=['sh', '-c'], | ||
arguments=['sleep 10; wget localhost:5678 -O /tmp/results.txt'], | ||
file_outputs={'downloaded': '/tmp/results.txt'})\ | ||
.add_toleration(V1Toleration(effect='NoSchedule', | ||
key='gpu', | ||
operator='Equal', | ||
value='run')) | ||
|
||
if __name__ == '__main__': | ||
# don't use top-level import of TektonCompiler to prevent monkey-patching KFP compiler when using KFP's dsl-compile | ||
from kfp_tekton.compiler import TektonCompiler | ||
TektonCompiler().compile(tolerations, __file__.replace('.py', '.yaml'), generate_pipelinerun=True) |
Oops, something went wrong.