Make namespace accessible in Task definition
A Task definition can not obtain the namespace it is running in. This is a request to make that namespace available, for example using context.namespace.
Relates to https://github.com/tektoncd/pipeline/issues/4540.
cc @vdemeester @jerop @KyWa
Thanks for the issue report. Our docs indicate there's already a variable Tasks can use: $(context.taskRun.namespace). You should be able to place this variable in your Task's definition and Tekton should replace it with the namespace that the Task is executing in (regardless if it's a pipelinerun or taskrun that executes it). If it doesn't then I reckon we should probably call this a bug and I can look into it.
Here's a small example to illustrate this:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: foo
spec:
steps:
- name: test-context
image: quay.io/openshift-pipeline/s2i
command: ['echo', '$(context.taskRun.namespace)']
And a PipelineRun that uses this Task:
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pr-test-foo
spec:
pipelineSpec:
tasks:
- name: try-foo
taskRef:
name: foo
And just for completeness' sake here's a TaskRun that also uses this Task:
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: tr-test-foo
spec:
taskRef:
name: foo
When I get the logs from the taskrun and pipelinerun pods I see default printed in both cases.
Edited to correct the PipelineRun yaml.
/priority awaiting-more-evidence
Sorry for the long delay, but just tested this (using the exact examples above sans image) and the TaskRun Pod logs just spits out: $(context.taskRun.namespace). I'm still tracking down the Tekton version, but its the OpenShift Pipelines Operator version 1.5. I'll get more info as soon as I can.
OpenShift Pipelines Operator version 1.5
This means it's Tekton 0.24.x you are using, which might not contain context.taskRun.namespace 🤔
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale with a justification.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/lifecycle stale
Send feedback to tektoncd/plumbing.
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/lifecycle rotten
Send feedback to tektoncd/plumbing.
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen with a justification.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.
/close
Send feedback to tektoncd/plumbing.
@tekton-robot: Closing this issue.
In response to this:
Rotten issues close after 30d of inactivity. Reopen the issue with
/reopenwith a justification. Mark the issue as fresh with/remove-lifecycle rottenwith a justification. If this issue should be exempted, mark the issue as frozen with/lifecycle frozenwith a justification./close
Send feedback to tektoncd/plumbing.
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.