Feature request
We already has experimental project cel
That's very useful, but one shortage: cannot evaluate expression with a predefined variable.
for example: job_priority in ['high', 'normal'] ? 'Sev-1' : 'Sev-2'
The job_priority
is a predefined variables somewhere.
To handle the gap, one solution is introduce the dependency between the param
s:
apiVersion: tekton.dev/v1alpha1
kind: Run
metadata:
generateName: celrun-with-context-
spec:
ref:
apiVersion: cel.tekton.dev/v1alpha1
kind: CEL
params:
- name: name
value: "'hello'"
- name: types
value: "type(name)"
- name: expression-use-context
value: "name + ' is type of ' + types"
basically, the idea is the subsequent param
could leverage previously param
for evaluation, see the type(name)
leverage the name
which is the first param
. it has been implements in the PR: tektoncd/experimental#717
That's could work, but not good enough, a better solution is to define a dedicated CRD for it, fortunately there is no CRD in cel for now.
A draft idea is:
apiVersion: custom.tekton.dev/v1alpha1
kind: CEL
metadata:
name: example
spec:
vars:
- name: job_priority
value: high
- name: alert_enable
value: "true"
We have vars
to store variables which will be leveraged by evaluation.
There should be two scenario:
apiVersion: tekton.dev/v1alpha1
kind: Run
metadata:
generateName: celrun-with-context-
spec:
ref:
apiVersion: custom.tekton.dev/v1alpha1
kind: CEL
name: example
params:
- name: job_severity
value: "job_priority in ['high', 'normal'] ? 'Sev-1' : 'Sev-2'"
- name: types
value: "type(job_severity)"
- name: alert_enable
value: "false"
Then the variables defined in CR: example
will be leveraged by evaluation, and after calculated the new expression and its result will be add to example
.
Run.spec.ref
with no name
apiVersion: tekton.dev/v1alpha1
kind: Run
metadata:
generateName: celrun-without-context-
spec:
ref:
apiVersion: custom.tekton.dev/v1alpha1
kind: CEL
params:
- name: red
value: "{'blue': '0x000080', 'red': '0xFF0000'}['red']"
- name: blue
value: "{'blue': '0x000080', 'red': '0xFF0000'}['blue']"
- name: is-red
value: "{'blue': '0x000080', 'red': '0xFF0000'}['red'] == '0xFF0000'"
- name: is-blue
value: "{'blue': '0x000080', 'red': '0xFF0000'}['blue'] == '0xFF0000'"
The behavior will keep same with current implements.
Need your feedback:
/cc @jerop @afrittoli
Use case