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

TaskRuns using ClusterTask don't sync the Annotations and Labels of the ClusterTask #7601

Closed
l-qing opened this issue Jan 23, 2024 · 1 comment · Fixed by #7602
Closed

TaskRuns using ClusterTask don't sync the Annotations and Labels of the ClusterTask #7601

l-qing opened this issue Jan 23, 2024 · 1 comment · Fixed by #7602
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@l-qing
Copy link
Contributor

l-qing commented Jan 23, 2024

Expected Behavior

TaskRuns that use ClusterTask can also synchronize Annotations and Labels in v0.56.0
Consistent with the behavior of Pipeline version v0.44.0

Actual Behavior

In version v0.56.0, the behavior of ClusterTask is inconsistent with that of tasks.
And also inconsistent with the behavior of ClusterTask in version v0.44.0.

Refs

  • The PR introducing this change: Replace v1beta1.TaskObject with *v1beta1.Task in TaskRun Reconciler #6471
  • func convertClusterTaskToTask(ctx context.Context, ct v1beta1.ClusterTask) (*v1.Task, error) {
    t := &v1beta1.Task{
    TypeMeta: metav1.TypeMeta{
    Kind: "Task",
    APIVersion: "tekton.dev/v1beta1",
    },
    }
    t.Spec = ct.Spec
    t.ObjectMeta.Name = ct.ObjectMeta.Name
  • // Store the fetched TaskSpec on the TaskRun for auditing
    if err := storeTaskSpecAndMergeMeta(ctx, tr, taskSpec, taskMeta); err != nil {
    logger.Errorf("Failed to store TaskSpec on TaskRun.Statusfor taskrun %s: %v", tr.Name, err)
    }
  • // Propagate annotations from Task to TaskRun. TaskRun annotations take precedences over Task.
    tr.ObjectMeta.Annotations = kmap.Union(kmap.ExcludeKeys(meta.Annotations, tknreconciler.KubectlLastAppliedAnnotationKey), tr.ObjectMeta.Annotations)
    // Propagate labels from Task to TaskRun. TaskRun labels take precedences over Task.
    tr.ObjectMeta.Labels = kmap.Union(meta.Labels, tr.ObjectMeta.Labels)
  • if !reflect.DeepEqual(tr.ObjectMeta.Labels, newTr.ObjectMeta.Labels) || !reflect.DeepEqual(tr.ObjectMeta.Annotations, newTr.ObjectMeta.Annotations) {
    // Note that this uses Update vs. Patch because the former is significantly easier to test.
    // If we want to switch this to Patch, then we will need to teach the utilities in test/controller.go
    // to deal with Patch (setting resourceVersion, and optimistic concurrency checks).
    newTr = newTr.DeepCopy()
    newTr.Labels = kmap.Union(newTr.Labels, tr.Labels)
    newTr.Annotations = kmap.Union(kmap.ExcludeKeys(newTr.Annotations, tknreconciler.KubectlLastAppliedAnnotationKey), tr.Annotations)
    return c.PipelineClientSet.TektonV1().TaskRuns(tr.Namespace).Update(ctx, newTr, metav1.UpdateOptions{})

Steps to Reproduce the Problem

  1. Prepare a YAML file test.clustertask.taskrun.yaml.
cat <<EOF > test.clustertask.taskrun.yaml
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
  name: clustertask-demo
  annotations:
    foo: bar
  labels:
    foo: bar
spec:
  steps:
    - name: echo
      image: ubuntu
      script: |
        #!/bin/sh
        echo "Hello World!"
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: taskrun-clustertask
  namespace: default
spec:
  taskRef:
    kind: ClusterTask
    name: clustertask-demo

---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: task-demo
  namespace: default
  annotations:
    foo: bar
  labels:
    foo: bar
spec:
  steps:
    - name: echo
      image: ubuntu
      script: |
        #!/bin/sh
        echo "Hello World!"
---
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: taskrun-task
  namespace: default
spec:
  taskRef:
    kind: Task
    name: task-demo
EOF
  1. Testing in Tekton Pipeline v0.44.0
    The taskrun-clustertask also has the annotations and labels of clustertask-demo.
  • kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.44.0/release.yaml
  • cat test.clustertask.taskrun.yaml | kubectl replace --force -f -
  • Result: kubectl get taskrun -n default taskrun-task taskrun-clustertask -o yaml
apiVersion: v1
items:
- apiVersion: tekton.dev/v1
  kind: TaskRun
  metadata:
    annotations:
      foo: bar
      pipeline.tekton.dev/release: 6db52ca
    creationTimestamp: "2024-01-23T09:32:46Z"
    generation: 1
    labels:
      app.kubernetes.io/managed-by: tekton-pipelines
      foo: bar
      tekton.dev/task: task-demo
    name: taskrun-task
    namespace: default
    resourceVersion: "7452"
    uid: bcc4eae1-425c-46ca-b899-777adaea1737
  spec:
    serviceAccountName: default
    taskRef:
      kind: Task
      name: task-demo
    timeout: 1h0m0s
  status:
    completionTime: "2024-01-23T09:38:39Z"
    conditions:
    - lastTransitionTime: "2024-01-23T09:38:39Z"
      message: All Steps have completed executing
      reason: Succeeded
      status: "True"
      type: Succeeded
    podName: taskrun-task-pod
    startTime: "2024-01-23T09:32:46Z"
    steps:
    - container: step-echo
      imageID: docker.io/library/ubuntu@sha256:e6173d4dc55e76b87c4af8db8821b1feae4146dd47341e4d431118c7dd060a74
      name: echo
      terminated:
        containerID: containerd://b19a40f3b8c1ba822259c53cd23328ccab277158d2a974c1b4fdf724915d0666
        exitCode: 0
        finishedAt: "2024-01-23T09:38:39Z"
        reason: Completed
        startedAt: "2024-01-23T09:38:39Z"
    taskSpec:
      steps:
      - computeResources: {}
        image: ubuntu
        name: echo
        script: |
          #!/bin/sh
          echo "Hello World!"
- apiVersion: tekton.dev/v1
  kind: TaskRun
  metadata:
    annotations:
      foo: bar
      pipeline.tekton.dev/release: 6db52ca
    creationTimestamp: "2024-01-23T09:32:46Z"
    generation: 1
    labels:
      app.kubernetes.io/managed-by: tekton-pipelines
      foo: bar
      tekton.dev/clusterTask: clustertask-demo
    name: taskrun-clustertask
    namespace: default
    resourceVersion: "7454"
    uid: cc20b2a6-4e62-4c0b-830f-abe5076cfed6
  spec:
    serviceAccountName: default
    taskRef:
      kind: ClusterTask
      name: clustertask-demo
    timeout: 1h0m0s
  status:
    completionTime: "2024-01-23T09:38:39Z"
    conditions:
    - lastTransitionTime: "2024-01-23T09:38:39Z"
      message: All Steps have completed executing
      reason: Succeeded
      status: "True"
      type: Succeeded
    podName: taskrun-clustertask-pod
    startTime: "2024-01-23T09:32:46Z"
    steps:
    - container: step-echo
      imageID: docker.io/library/ubuntu@sha256:e6173d4dc55e76b87c4af8db8821b1feae4146dd47341e4d431118c7dd060a74
      name: echo
      terminated:
        containerID: containerd://47ed41054816b0e19be79fb1b3cfa38395648d01ae652a2360692859d2c2ac05
        exitCode: 0
        finishedAt: "2024-01-23T09:38:38Z"
        reason: Completed
        startedAt: "2024-01-23T09:38:38Z"
    taskSpec:
      steps:
      - computeResources: {}
        image: ubuntu
        name: echo
        script: |
          #!/bin/sh
          echo "Hello World!"
kind: List
metadata:
  resourceVersion: ""
  1. Testing in Tekton Pipeline v0.56.0
    The taskrun-clustertask lacks the annotations and labels of clustertask-demo.
  • kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.56.0/release.yaml
  • cat test.clustertask.taskrun.yaml | kubectl replace --force -f -
  • Result: kubectl get taskrun -n default taskrun-task taskrun-clustertask -o yaml
apiVersion: v1
items:
- apiVersion: tekton.dev/v1
  kind: TaskRun
  metadata:
    annotations:
      foo: bar
      pipeline.tekton.dev/release: e1c7828
    creationTimestamp: "2024-01-23T09:55:07Z"
    generation: 1
    labels:
      app.kubernetes.io/managed-by: tekton-pipelines
      foo: bar
      tekton.dev/task: task-demo
    name: taskrun-task
    namespace: default
    resourceVersion: "13671"
    uid: 60ba69a0-fdcb-4856-9ce3-f2b35fa411c6
  spec:
    serviceAccountName: default
    taskRef:
      kind: Task
      name: task-demo
    timeout: 1h0m0s
  status:
    completionTime: "2024-01-23T09:55:19Z"
    conditions:
    - lastTransitionTime: "2024-01-23T09:55:19Z"
      message: All Steps have completed executing
      reason: Succeeded
      status: "True"
      type: Succeeded
    podName: taskrun-task-pod
    provenance:
      featureFlags:
        AwaitSidecarReadiness: true
        Coschedule: workspaces
        DisableAffinityAssistant: false
        DisableCredsInit: false
        EnableAPIFields: beta
        EnableCELInWhenExpression: false
        EnableKeepPodOnCancel: false
        EnableParamEnum: false
        EnableProvenanceInStatus: true
        EnableStepActions: false
        EnableTektonOCIBundles: false
        EnforceNonfalsifiability: none
        MaxResultSize: 4096
        RequireGitSSHSecretKnownHosts: false
        ResultExtractionMethod: termination-message
        RunningInEnvWithInjectedSidecars: true
        ScopeWhenExpressionsToTask: false
        SendCloudEventsForRuns: false
        SetSecurityContext: false
        VerificationNoMatchPolicy: ignore
    startTime: "2024-01-23T09:55:07Z"
    steps:
    - container: step-echo
      imageID: docker.io/library/ubuntu@sha256:e6173d4dc55e76b87c4af8db8821b1feae4146dd47341e4d431118c7dd060a74
      name: echo
      terminated:
        containerID: containerd://b1e7dc91fad33fb5f9610ba811887b61ad1646de678aaad096118f5318174dec
        exitCode: 0
        finishedAt: "2024-01-23T09:55:18Z"
        reason: Completed
        startedAt: "2024-01-23T09:55:18Z"
    taskSpec:
      steps:
      - computeResources: {}
        image: ubuntu
        name: echo
        script: |
          #!/bin/sh
          echo "Hello World!"
- apiVersion: tekton.dev/v1
  kind: TaskRun
  metadata:
    annotations:
      pipeline.tekton.dev/release: e1c7828
    creationTimestamp: "2024-01-23T09:55:07Z"
    generation: 1
    labels:
      app.kubernetes.io/managed-by: tekton-pipelines
      tekton.dev/clusterTask: clustertask-demo
    name: taskrun-clustertask
    namespace: default
    resourceVersion: "13652"
    uid: 1baf9ca8-a108-4a0b-8c75-1bcb0cc520c8
  spec:
    serviceAccountName: default
    taskRef:
      kind: ClusterTask
      name: clustertask-demo
    timeout: 1h0m0s
  status:
    completionTime: "2024-01-23T09:55:17Z"
    conditions:
    - lastTransitionTime: "2024-01-23T09:55:17Z"
      message: All Steps have completed executing
      reason: Succeeded
      status: "True"
      type: Succeeded
    podName: taskrun-clustertask-pod
    provenance:
      featureFlags:
        AwaitSidecarReadiness: true
        Coschedule: workspaces
        DisableAffinityAssistant: false
        DisableCredsInit: false
        EnableAPIFields: beta
        EnableCELInWhenExpression: false
        EnableKeepPodOnCancel: false
        EnableParamEnum: false
        EnableProvenanceInStatus: true
        EnableStepActions: false
        EnableTektonOCIBundles: false
        EnforceNonfalsifiability: none
        MaxResultSize: 4096
        RequireGitSSHSecretKnownHosts: false
        ResultExtractionMethod: termination-message
        RunningInEnvWithInjectedSidecars: true
        ScopeWhenExpressionsToTask: false
        SendCloudEventsForRuns: false
        SetSecurityContext: false
        VerificationNoMatchPolicy: ignore
    startTime: "2024-01-23T09:55:07Z"
    steps:
    - container: step-echo
      imageID: docker.io/library/ubuntu@sha256:e6173d4dc55e76b87c4af8db8821b1feae4146dd47341e4d431118c7dd060a74
      name: echo
      terminated:
        containerID: containerd://89e19e8b87b53226889212ee8f2af1e09bb51fad125a9261acc53ba0c10f5cc3
        exitCode: 0
        finishedAt: "2024-01-23T09:55:16Z"
        reason: Completed
        startedAt: "2024-01-23T09:55:16Z"
    taskSpec:
      steps:
      - computeResources: {}
        image: ubuntu
        name: echo
        script: |
          #!/bin/sh
          echo "Hello World!"
kind: List
metadata:
  resourceVersion: ""

Additional Info

  • Kubernetes version:

    Output of kubectl version:

Client Version: v1.29.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.26.0
WARNING: version difference between client (1.29) and server (1.26) exceeds the supported minor version skew of +/-1
  • Tekton Pipeline version:

    Output of tkn version or kubectl get pods -n tekton-pipelines -l app=tekton-pipelines-controller -o=jsonpath='{.items[0].metadata.labels.version}'

v0.56.0

/kind bug

@l-qing l-qing added the kind/bug Categorizes issue or PR as related to a bug. label Jan 23, 2024
@l-qing
Copy link
Contributor Author

l-qing commented Jan 23, 2024

/assign

l-qing added a commit to l-qing/pipeline that referenced this issue Jan 23, 2024
l-qing added a commit to l-qing/pipeline that referenced this issue Jan 25, 2024
l-qing added a commit to l-qing/pipeline that referenced this issue Jan 28, 2024
l-qing added a commit to l-qing/pipeline that referenced this issue Jan 31, 2024
l-qing added a commit to l-qing/pipeline that referenced this issue Feb 7, 2024
l-qing added a commit to l-qing/pipeline that referenced this issue Feb 8, 2024
l-qing added a commit to l-qing/pipeline that referenced this issue Feb 10, 2024
tekton-robot pushed a commit to tekton-robot/pipeline that referenced this issue Feb 12, 2024
tekton-robot pushed a commit to tekton-robot/pipeline that referenced this issue Feb 12, 2024
tekton-robot pushed a commit to tekton-robot/pipeline that referenced this issue Feb 12, 2024
l-qing added a commit to katanomi/pipeline that referenced this issue Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant