# 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: recursion-pipeline annotations: tekton.dev/output_artifacts: '{"flip-coin": [{"key": "artifacts/$PIPELINERUN/flip-coin/output.tgz", "name": "flip-coin-output", "path": "/tmp/outputs/output/data"}], "flip-coin-2": [{"key": "artifacts/$PIPELINERUN/flip-coin-2/output.tgz", "name": "flip-coin-2-output", "path": "/tmp/outputs/output/data"}]}' tekton.dev/input_artifacts: '{"print": [{"name": "flip-coin-output", "parent_task": "flip-coin"}], "print-2": [{"name": "flip-coin-output", "parent_task": "flip-coin"}]}' tekton.dev/artifact_bucket: mlpipeline tekton.dev/artifact_endpoint: minio-service.kubeflow:9000 tekton.dev/artifact_endpoint_scheme: http:// tekton.dev/artifact_items: '{"flip-coin": [["output", "$(results.output.path)"]], "flip-coin-2": [["output", "$(results.output.path)"]], "print": [], "print-2": []}' 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": "shows how to use graph_component and recursion.", "inputs": [{"default": "12", "name": "maxVal", "optional": true, "type": "Integer"}], "name": "recursion-pipeline"}' tekton.dev/resource_templates: '[{"apiVersion": "custom.tekton.dev/v1alpha1", "kind": "PipelineLoop", "metadata": {"name": "recursion-pipeline-flip-component-1"}, "spec": {"iterateParam": "just_one_iteration", "pipelineSpec": {"params": [{"name": "flip-coin-output", "type": "string"}, {"name": "just_one_iteration", "type": "string"}, {"name": "maxVal", "type": "string"}], "tasks": [{"name": "print", "params": [{"name": "flip-coin-output", "value": "$(params.flip-coin-output)"}], "taskSpec": {"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest": "{\"name\": \"print\", \"outputs\": [], \"version\": \"print@sha256=8232f0c48ead41f53f1c61e3c35a4d3440cdd0591ab17933736e5ed7c8390d5c\"}", "tekton.dev/template": ""}, "labels": {"pipelines.kubeflow.org/cache_enabled": "true", "pipelines.kubeflow.org/generation": "", "pipelines.kubeflow.org/pipelinename": ""}}, "params": [{"name": "flip-coin-output", "type": "string"}], "steps": [{"command": ["echo", "$(inputs.params.flip-coin-output)"], "image": "alpine:3.6", "name": "main"}]}, "timeout": "525600m", "when": [{"input": "$(tasks.condition-2.results.outcome)", "operator": "in", "values": ["true"]}]}, {"name": "flip-coin-2", "runAfter": ["print"], "taskSpec": {"metadata": {"annotations": {"pipelines.kubeflow.org/component_spec_digest": "{\"name\": \"flip-coin\", \"outputs\": [{\"name\": \"output\", \"type\": \"String\"}], \"version\": \"flip-coin@sha256=1989ae83915edcd7253e495603317c1f99196f5ef2b0bacb31a0273d941e830d\"}", "tekton.dev/template": ""}, "labels": {"pipelines.kubeflow.org/cache_enabled": "true", "pipelines.kubeflow.org/generation": "", "pipelines.kubeflow.org/pipelinename": ""}}, "results": [{"description": "/tmp/outputs/output/data", "name": "output", "type": "string"}], "steps": [{"args": ["python -c \"import random; result = ''heads'' if random.randint(0,1) == 0 else ''tails''; print(result)\" | tee $0\n", "$(results.output.path)"], "command": ["sh", "-c"], "image": "python:alpine3.6", "name": "main"}]}, "timeout": "525600m", "when": [{"input": "$(tasks.condition-2.results.outcome)", "operator": "in", "values": ["true"]}]}, {"name": "condition-2", "params": [{"name": "operand1", "value": "$(params.flip-coin-output)"}, {"name": "operand2", "value": "heads"}, {"name": "operator", "value": "=="}], "taskSpec": {"metadata": {"labels": {"pipelines.kubeflow.org/cache_enabled": "true", "pipelines.kubeflow.org/generation": "", "pipelines.kubeflow.org/pipelinename": ""}}, "params": [{"name": "operand1", "type": "string"}, {"name": "operand2", "type": "string"}, {"name": "operator", "type": "string"}], "results": [{"description": "Conditional task outcome", "name": "outcome", "type": "string"}], "steps": [{"args": ["import sys\ninput1=str.rstrip(sys.argv[1])\ninput2=str.rstrip(sys.argv[2])\ntry:\n input1=int(input1)\n input2=int(input2)\nexcept:\n input1=str(input1)\noutcome=\"true\" if (input1 $(inputs.params.operator) input2) else \"false\"\nf = open(\"/tekton/results/outcome\", \"w\")\nf.write(outcome)\nf.close()\n", "$(inputs.params.operand1)", "$(inputs.params.operand2)"], "command": ["sh", "-ec", "program_path=$(mktemp); printf \"%s\" \"$0\" > \"$program_path\"; python3 -u \"$program_path\" \"$1\" \"$2\""], "image": "python:alpine3.6", "name": "main"}]}}, {"name": "flip-component", "params": [{"name": "flip-coin-output", "value": "$(tasks.flip-coin-2.results.output)"}, {"name": "just_one_iteration", "value": ["1"]}, {"name": "maxVal", "value": "$(params.maxVal)"}], "taskRef": {"apiVersion": "custom.tekton.dev/v1alpha1", "kind": "PipelineLoop", "name": "recursion-pipeline-flip-component-1"}, "when": [{"input": "$(tasks.condition-2.results.outcome)", "operator": "in", "values": ["true"]}]}]}}}]' spec: params: - name: maxVal value: '12' pipelineSpec: params: - name: maxVal default: '12' tasks: - name: flip-coin taskSpec: steps: - name: main args: - | python -c "import random; result = 'heads' if random.randint(0,1) == 0 else 'tails'; print(result)" | tee $0 - $(results.output.path) command: - sh - -c image: python:alpine3.6 results: - name: output type: string description: /tmp/outputs/output/data metadata: labels: pipelines.kubeflow.org/pipelinename: '' pipelines.kubeflow.org/generation: '' pipelines.kubeflow.org/cache_enabled: "true" annotations: pipelines.kubeflow.org/component_spec_digest: '{"name": "flip-coin", "outputs": [{"name": "output", "type": "String"}], "version": "flip-coin@sha256=1989ae83915edcd7253e495603317c1f99196f5ef2b0bacb31a0273d941e830d"}' tekton.dev/template: '' timeout: 525600m - name: print-2 params: - name: flip-coin-output value: $(tasks.flip-coin.results.output) taskSpec: steps: - name: main command: - echo - cool, it is over. $(inputs.params.flip-coin-output) image: alpine:3.6 params: - name: flip-coin-output metadata: labels: pipelines.kubeflow.org/pipelinename: '' pipelines.kubeflow.org/generation: '' pipelines.kubeflow.org/cache_enabled: "true" annotations: pipelines.kubeflow.org/component_spec_digest: '{"name": "print", "outputs": [], "version": "print@sha256=8232f0c48ead41f53f1c61e3c35a4d3440cdd0591ab17933736e5ed7c8390d5c"}' tekton.dev/template: '' runAfter: - recursion-pipeline-flip-component-1 timeout: 525600m - runAfter: - flip-coin name: recursion-pipeline-flip-component-1 taskRef: apiVersion: custom.tekton.dev/v1alpha1 kind: PipelineLoop name: recursion-pipeline-flip-component-1 params: - name: flip-coin-output value: $(tasks.flip-coin.results.output) - name: just_one_iteration value: - '1' - name: maxVal value: $(params.maxVal) timeout: 525600m