pipeline icon indicating copy to clipboard operation
pipeline copied to clipboard

Make namespace accessible in Task definition

Open tmds opened this issue 3 years ago • 6 comments

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

tmds avatar Mar 29 '22 12:03 tmds

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.

ghost avatar Mar 29 '22 16:03 ghost

/priority awaiting-more-evidence

ghost avatar Mar 29 '22 17:03 ghost

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.

KyWa avatar May 04 '22 22:05 KyWa

OpenShift Pipelines Operator version 1.5

This means it's Tekton 0.24.x you are using, which might not contain context.taskRun.namespace 🤔

vdemeester avatar May 05 '22 08:05 vdemeester

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.

tekton-robot avatar Aug 03 '22 08:08 tekton-robot

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.

tekton-robot avatar Sep 02 '22 09:09 tekton-robot

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 avatar Oct 02 '22 09:10 tekton-robot

@tekton-robot: Closing this issue.

In response to this:

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.

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.

tekton-robot avatar Oct 02 '22 09:10 tekton-robot