-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[TEP-0048] Add support for default results #5620
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| apiVersion: tekton.dev/v1beta1 | ||
| kind: PipelineRun | ||
| metadata: | ||
| name: pipelinerun-emit-default-results | ||
| spec: | ||
| pipelineSpec: | ||
| tasks: | ||
| - name: task1 | ||
| taskSpec: | ||
| results: | ||
| - name: array-results | ||
| type: array | ||
| description: The array results | ||
| default: | ||
| - "1" | ||
| - "2" | ||
| - "3" | ||
| steps: | ||
| - name: write-array | ||
| image: bash:latest | ||
| script: | | ||
| #!/usr/bin/env bash | ||
| echo -n "this script won't emit array result" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to highlight the issue #3497 which probably seems to go against this example?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The discussion in that issue hasn't come to a conclusion so this might be ok for now. I wonder if your examples could genuinely error out and the steps have an |
||
| - name: task2 | ||
| taskSpec: | ||
| results: | ||
| - name: object-results | ||
| type: object | ||
| description: The object results | ||
| properties: | ||
| foo: {type: string} | ||
| hello: {type: string} | ||
| default: | ||
| foo: bar | ||
| hello: world | ||
| steps: | ||
| - name: write-array | ||
| image: bash:latest | ||
| script: | | ||
| #!/usr/bin/env bash | ||
| echo -n "this script won't emit object result" | ||
| results: | ||
| - name: array-results | ||
| type: array | ||
| description: whole array | ||
| value: $(tasks.task1.results.array-results[*]) | ||
| - name: array-results-from-array-indexing-and-object-elements | ||
| type: array | ||
| description: whole array | ||
| value: | ||
| [ | ||
| "$(tasks.task1.results.array-results[0])", | ||
| "$(tasks.task2.results.object-results.foo)", | ||
| ] | ||
| - name: array-indexing-results | ||
| type: string | ||
| description: array element | ||
| value: $(tasks.task1.results.array-results[1]) | ||
| - name: object-results | ||
| type: object | ||
| description: whole object | ||
| value: $(tasks.task2.results.object-results[*]) | ||
| - name: object-results-from-array-indexing-and-object-elements | ||
| type: object | ||
| description: whole object | ||
| value: | ||
| key1: $(tasks.task1.results.array-results[1]) | ||
| key2: $(tasks.task2.results.object-results.hello) | ||
| - name: object-element | ||
| type: string | ||
| description: object element | ||
| value: $(tasks.task2.results.object-results.foo) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| apiVersion: tekton.dev/v1beta1 | ||
| kind: TaskRun | ||
| metadata: | ||
| generateName: default-result-run- | ||
| spec: | ||
| taskSpec: | ||
| results: | ||
| - name: result1 | ||
| description: will be produced | ||
| - name: string-result | ||
| description: will not be produced by step but has default value | ||
| default: "string value" | ||
| - name: array-result | ||
| description: default array result will be produced | ||
| default: | ||
| - "foo" | ||
| - "bar" | ||
| - name: eight-results | ||
| type: object | ||
| properties: | ||
| IMAGE_URL: {type: string} | ||
| IMAGE_DIGEST: {type: string} | ||
| default: | ||
| IMAGE_URL: "default.com" | ||
| IMAGE_DIGEST: "defaultsha" | ||
| steps: | ||
| - name: failing-step | ||
| onError: continue | ||
| image: busybox | ||
| script: | | ||
| echo -n 123 | tee $(results.result1.path) | ||
| exit 1 | ||
| echo -n 456 | tee $(results.string-result.path) | ||
|
Comment on lines
+30
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can assert the emitted results like https://github.com/tektoncd/pipeline/blob/07bf4702e6d6b35bdff40ed760cf3280b74c4375/examples/v1beta1/taskruns/alpha/emit-array-results.yaml But it's optional |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,23 @@ func (r TaskResult) convertTo(ctx context.Context, sink *v1.TaskResult) { | |
| properties[k] = v1.PropertySpec{Type: v1.ParamType(v.Type)} | ||
| } | ||
| sink.Properties = properties | ||
| if r.Default != nil { | ||
| sink.Default = &v1.ParamValue{ | ||
| Type: v1.ParamType(r.Default.Type), | ||
| } | ||
| switch r.Default.Type { | ||
| case ParamTypeString: | ||
| sink.Default.StringVal = r.Default.StringVal | ||
| case ParamTypeArray: | ||
| sink.Default.ArrayVal = r.Default.ArrayVal | ||
| default: // In case of ParamTypeObject | ||
| defaults := make(map[string]string) | ||
| for k, v := range r.Default.ObjectVal { | ||
| defaults[k] = v | ||
| } | ||
| sink.Default.ObjectVal = defaults | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (r *TaskResult) convertFrom(ctx context.Context, source v1.TaskResult) { | ||
|
|
@@ -26,4 +43,21 @@ func (r *TaskResult) convertFrom(ctx context.Context, source v1.TaskResult) { | |
| properties[k] = PropertySpec{Type: ParamType(v.Type)} | ||
| } | ||
| r.Properties = properties | ||
| if source.Default != nil { | ||
|
vinamra28 marked this conversation as resolved.
|
||
| r.Default = &ParamValue{ | ||
| Type: ParamType(source.Default.Type), | ||
| } | ||
| switch source.Default.Type { | ||
| case v1.ParamTypeString: | ||
| r.Default.StringVal = source.Default.StringVal | ||
| case v1.ParamTypeArray: | ||
| r.Default.ArrayVal = source.Default.ArrayVal | ||
| default: | ||
| defaults := make(map[string]string) | ||
| for k, v := range source.Default.ObjectVal { | ||
| defaults[k] = v | ||
| } | ||
| r.Default.ObjectVal = defaults | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems to be the same logic as in lines 18:34. May be wrap it into a function and call it here? |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.