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

Substitute params by index #3044

Closed
popcor255 opened this issue Aug 3, 2020 · 5 comments
Closed

Substitute params by index #3044

popcor255 opened this issue Aug 3, 2020 · 5 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@popcor255
Copy link
Member

popcor255 commented Aug 3, 2020

Feature request

Currently prams can be substituted by key (string substitute). However, params is an array of type param. I would like to reference a parameter by the index in the params array rather than the key.

TLDR; Array of Type Params is not the same as Param that is Type Array. We should probably fix this.

(how array access would look)
Request:

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: simple-task
spec:
  params:
    - name: param
      type: string
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params[0])" ]
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: simple-task
spec:
  params:
    - name: param
      type: array
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params[0][*])" ]

The above tasks should produce the same result as these tasks:

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: simple-task
spec:
  params:
    - name: param
      type: string
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params.param)" ]
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: simple-task
spec:
  params:
    - name: param
      type: array
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params.param[*])" ]

These two tasks should produce the same result.
Note : This implementation requires indexes to be declared before runtime.

@popcor255 popcor255 added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 3, 2020
@bobcatfish
Copy link
Collaborator

Related issue: #1393 <-- in that issue I believe @skaegi is suggesting a broader syntax for accessing param values (i think jsonpath based?)

I think we could totally tackle the features one at a time if that's easiest, as long as they are all headed in the same direction - and afaik the syntax above is how array access would look?

might be worth bringing up in the API wg too: https://github.com/tektoncd/community/blob/master/working-groups.md#api

@popcor255
Copy link
Member Author

I added the example with array types. It is just using bracket annotation instead of dot annotation. However, with bracket annotation we can use the type to distinguish index(int)/key(string).

@popcor255
Copy link
Member Author

popcor255 commented Aug 3, 2020

Quick and Dirty POC: https://github.com/popcor255/pipeline/tree/replace-by-index-without-validation
It was like 2 line code change o _o

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: simple-task
spec:
  params:
    - name: param
      type: string
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params.0)" ]

@popcor255
Copy link
Member Author

The main issue I am trying to highlight is that an Array of Type Params is not the same as Param that is Type Array. I think there should be a discussion on if there should be some effort on keeping them the same or at the very least have a clear distinction.

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: sleepy-with-nested-params
spec:
  params:
    - name: myParams
      type: array
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params.myParams[*])" ]
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  generateName: run-with-sleepy-with-nested-params
spec:
  taskRef:
    name: sleepy-with-nested-params
  params:
    - name: myParams
      value:
        - "test=testing"
        - "env=test"
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: sleepy-with-psuedo-params
spec:
  params:
    - name: test
    - name: env
  steps:
  - name: alpine
    image: alpine
    command: [ "echo" ]
    args: [ "$(params[*])" ]
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  generateName: run-with-sleepy-with-psuedo-params
spec:
  taskRef:
    name: sleepy-with-psuedo-params
  params:
    - name: test
      value: testing
    - name: env
      value: testing

@popcor255 popcor255 changed the title [WIP] Substitute params by index Substitute params by index Aug 3, 2020
@popcor255
Copy link
Member Author

#1020
/close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants