@@ -33,6 +33,7 @@ import (
3333 v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
3434 "github.com/tektoncd/pipeline/pkg/internal/computeresources/tasklevel"
3535 "github.com/tektoncd/pipeline/pkg/names"
36+ tknreconciler "github.com/tektoncd/pipeline/pkg/reconciler"
3637 "github.com/tektoncd/pipeline/pkg/spire"
3738 corev1 "k8s.io/api/core/v1"
3839 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,6 +42,7 @@ import (
4142 "k8s.io/client-go/kubernetes"
4243 "k8s.io/utils/strings/slices"
4344 "knative.dev/pkg/changeset"
45+ "knative.dev/pkg/kmap"
4446 "knative.dev/pkg/kmeta"
4547)
4648
@@ -159,6 +161,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta
159161 enableKeepPodOnCancel := featureFlags .EnableKeepPodOnCancel
160162 setSecurityContext := config .FromContextOrDefaults (ctx ).FeatureFlags .SetSecurityContext
161163 setSecurityContextReadOnlyRootFilesystem := config .FromContextOrDefaults (ctx ).FeatureFlags .SetSecurityContextReadOnlyRootFilesystem
164+ defaultManagedByLabelValue := config .FromContextOrDefaults (ctx ).Defaults .DefaultManagedByLabelValue
162165
163166 // Add our implicit volumes first, so they can be overridden by the user if they prefer.
164167 volumes = append (volumes , implicitVolumes ... )
@@ -459,7 +462,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta
459462 priorityClassName = * podTemplate .PriorityClassName
460463 }
461464
462- podAnnotations := kmeta .CopyMap (taskRun .Annotations )
465+ podAnnotations := kmap . ExcludeKeys ( kmeta .CopyMap (taskRun .Annotations ), tknreconciler . KubernetesManagedByAnnotationKey )
463466 podAnnotations [ReleaseAnnotation ] = changeset .Get ()
464467
465468 if readyImmediately {
@@ -491,7 +494,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta
491494 * metav1 .NewControllerRef (taskRun , groupVersionKind ),
492495 },
493496 Annotations : podAnnotations ,
494- Labels : makeLabels (taskRun ),
497+ Labels : makeLabels (taskRun , defaultManagedByLabelValue ),
495498 },
496499 Spec : corev1.PodSpec {
497500 RestartPolicy : corev1 .RestartPolicyNever ,
@@ -529,7 +532,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta
529532}
530533
531534// makeLabels constructs the labels we will propagate from TaskRuns to Pods.
532- func makeLabels (s * v1.TaskRun ) map [string ]string {
535+ func makeLabels (s * v1.TaskRun , defaultManagedByLabelValue string ) map [string ]string {
533536 labels := make (map [string ]string , len (s .ObjectMeta .Labels )+ 1 )
534537 // NB: Set this *before* passing through TaskRun labels. If the TaskRun
535538 // has a managed-by label, it should override this default.
@@ -543,6 +546,8 @@ func makeLabels(s *v1.TaskRun) map[string]string {
543546 // specifies this label, it should be overridden by this value.
544547 labels [pipeline .TaskRunLabelKey ] = s .Name
545548 labels [pipeline .TaskRunUIDLabelKey ] = string (s .UID )
549+ // Enforce app.kubernetes.io/managed-by to be the value configured
550+ labels [tknreconciler .KubernetesManagedByAnnotationKey ] = defaultManagedByLabelValue
546551 return labels
547552}
548553
0 commit comments