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

Variable interpolations for a TaskRun's name, etc. #1522

Closed
imjasonh opened this issue Nov 4, 2019 · 16 comments
Closed

Variable interpolations for a TaskRun's name, etc. #1522

imjasonh opened this issue Nov 4, 2019 · 16 comments
Assignees
Labels
kind/design Categorizes issue or PR as related to design. kind/feature Categorizes issue or PR as related to a new feature.

Comments

@imjasonh
Copy link
Member

imjasonh commented Nov 4, 2019

Expected Behavior

I'm able to reference the name of the TaskRun (and PipelineRun) I'm running inside of, from within the execution context.

Actual Behavior

I am not.

Additional Info

We could support this using variable interpolation, with a placeholder like $(inputs.taskRunName) or $(inputs.pipelineRunName) etc. -- if the TaskRun is not part of a PipelineRun its name should be "" (or possibly be flagged as invalid?)

There could also be variables for task name and pipeline name ($(inputs.taskName), etc.), which could also be "" (or invalid) if the TaskRun is not running from a predefined, named Task.

If we do this it probably also makes sense to be able to inject the namespace ($(inputs.namespace) and $(inputs.taskNamespace), since they can be in different namespaces. If it's a cluster-scoped Task, taskNamespace could be "" (or invalid, some sentinel value).

cc @csantanapr

/kind feature
/kind design

@imjasonh imjasonh added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 4, 2019
@tekton-robot tekton-robot added the kind/design Categorizes issue or PR as related to design. label Nov 4, 2019
@skaegi
Copy link
Contributor

skaegi commented Nov 4, 2019

Tekton uses labels pretty effectively so you can use an "env" valueFrom with fieldRef to get most Tekton information. For example inside a Step you can do...

env:
  - name: TASK
    valueFrom:
      fieldRef:
        fieldPath: metadata.labels['tekton.dev/task']

That works for tekton.dev/pipeline, tekton.dev/pipelineRun, tekton.dev/pipelineTask, tekton.dev/task, and tekton.dev/taskRun

Alternately you can use the Downward API to mount the labels as a volume to roughly the same effect.

All in all I think this is probably sufficient for now and we should consider closing.

@vdemeester
Copy link
Member

@skaegi there is one trick to it though, those labels are on TaskRun and PipelineRun, but not on Task and Pipeline — I don't think it's a big deal as if we need it in the Task we may use parameters for it.

@imjasonh overall, I tend to agree with @skaegi, not sure it is required as of today, that said, it might be nice to have that "easy" variable interpolation in the future.

@csantanapr
Copy link

I was able to use fieldRef to get the namespace.

What about using this values in conditions for example if namespace is “prod” skip this step or add this step. Is that possible today?

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 11, 2020

/assign R2wenD2

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 15, 2020

Since (inputs) is no longer a field on the resource, I'll use (runtime.) as the way to access names.

@bobcatfish
Copy link
Collaborator

Totally minor thing but in the working group update this morning i was typing runtime.taskRunName and i'm wondering if it would make sense to make it runtime.taskRun.name in case we want to expose other taskRun type attributes one day (e.g. startTime or something)

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 18, 2020

Rather than runtime, lets use context.taskRunName so that the term runtime doesn't become overloaded. Please let me know if there are any concerns with adding a context scope.

@bobcatfish
Copy link
Collaborator

context sounds good to me!

@R2wenD2 what do you think about context.taskRun.name to open up the possibility of other taskRun attributes one day?

@jlpettersson
Copy link
Member

I liked the idea with metadata.name since that is the actual field name. E.g. it is used in Downward API: fieldPath

@bobcatfish
Copy link
Collaborator

I liked the idea with metadata.name since that is the actual field name

If we go that path I think we'd still want to scope it since it might not be clear which object's metadata you're talking about, e.g. context.taskRun.metadata.name or taskRun.metadata.name

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 22, 2020

I prefer context.taskRun.metadata.name - it makes it clear that we're using the name provided in the metadata for the taskRun (or pipeline, or pipelinerun) that is being run in the current context.

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 22, 2020

I'll use "" as the default value for the name if a taskRun isn't a part of a pipelineRun.

@jlpettersson
Copy link
Member

If it will start with context.taskRun.*

I think also context.taskRun.name would be a viable alternative. In the Go types, that is a shortcut for metadata.name. Then we keep that name slightly shorter for the end-users.

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jun 25, 2020

After some investigation, (and discussion with @bobcatfish) It makes sense to make the context.pipelineRun.name available to the pipeline and context.taskRun.Name available to the task, using "" as a default when there is no taskRun or PipelineRun.

@R2wenD2
Copy link
Contributor

R2wenD2 commented Jul 10, 2020

/close

@tekton-robot
Copy link
Collaborator

@R2wenD2: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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

No branches or pull requests

8 participants