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 details for param variable replacement as a whole in TEP076 #707

Merged
merged 3 commits into from
Aug 22, 2022
Merged
Changes from 2 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
36 changes: 34 additions & 2 deletions teps/0076-array-result-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,27 @@ tasks:
Additionally, array results can be passed directly to Tasks which take arrays as parameters using
[the `[*]` variable replacement syntax](https://github.com/tektoncd/pipeline/blob/main/docs/tasks.md#substituting-array-parameters).

For example:

For example, when params `update-all-environments` in array type is substituted with another array type `tasks.get-environments.results.environments`:
```yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
...
spec:
tasks:
- name: update-all-environments
params:
- name: environments
value: $(tasks.get-environments.results.environments[*])
ywluogg marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

@chuangw6 chuangw6 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first two examples are overlapping. We don't need to distinguish whether the variable reference is quoted or not. It's just K8s default behaviour to treat any value as string if it's not array or dictionary no matter if it is quoted (doc). i.e.

params:
      - name: environments
        value: abc

is equivalent to

params:
      - name: environments
        value: "abc"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first two examples are overlapping. We don't need to distinguish whether the variable reference is quoted or not. It's just K8s default behaviour to treat any value as string if it's not array or dictionary no matter if it is quoted (doc).

I believe that the yaml and json conversions are through K8S API (OpenAPI) and it is generated through swagger.json
And the value field under params is marshaled and unmarshaled by the implemented json.Unmarshaller interface in params_types.go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a functional difference between how value: foo and value: "foo" is interpreted though? (e.g. they would come in as a string, but we'd recognize the [*] syntax and treat it like an array)

```
What we will get will be:
```
params:
- name: environments
value:
- 'value1'
- 'value2'
```
Another example will be the following if `tasks.get-environments.results.environments` and `environments` are both arrays of strings:
```yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
Expand All @@ -465,6 +484,19 @@ tasks:
- name: environments
value: '$(tasks.get-environments.results.environments[*])'
```
A third way for variable replacements can be:
```yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
...
spec:
tasks:
- name: update-all-environments
params:
- name: environments
value:
- '$(tasks.get-environments.results.environments[*])'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see another benefit of supporting this in array is that we can append several results. But for Object it may not be so helpful? @chuangw6 thinks we shouldn't add support for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For array, this variable replacement makes sense to me.

For object, it's different. I'll discuss with you offline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I should've be more clear about this, but since 0076 is all around arrays, so I will only focus on examples for arrays. I will open another PR for 0075 if necessary, once we finalize our discussions in tektoncd/pipeline#4879

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be clear, this is an alternative approach right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'd interpret this syntax as "an array element that holds an array", which is different than the previous 2 examples. Nested arrays are a non-goal for this PR, so perhaps we should omit this?

```

## Test Plan

Expand Down