diff --git a/config/config-observability.yaml b/config/config-observability.yaml index 5d8d49064eb..5d5d9caecf1 100644 --- a/config/config-observability.yaml +++ b/config/config-observability.yaml @@ -37,17 +37,18 @@ data: # metrics.backend-destination field specifies the system metrics destination. # It supports either prometheus (the default) or stackdriver. - # Note: Using stackdriver will incur additional charges + # Note: Using Stackdriver will incur additional charges. metrics.backend-destination: prometheus - # metrics.stackdriver-project-id field specifies the stackdriver project ID. This + # metrics.stackdriver-project-id field specifies the Stackdriver project ID. This # field is optional. When running on GCE, application default credentials will be - # used if this field is not provided. + # used and metrics will be sent to the cluster's project if this field is + # not provided. metrics.stackdriver-project-id: "" - # metrics.allow-stackdriver-custom-metrics indicates whether it is allowed to send metrics to - # Stackdriver using "global" resource type and custom metric type if the - # metrics are not supported by "knative_revision" resource type. Setting this - # flag to "true" could cause extra Stackdriver charge. - # If metrics.backend-destination is not Stackdriver, this is ignored. + # metrics.allow-stackdriver-custom-metrics indicates whether it is allowed + # to send metrics to Stackdriver using "global" resource type and custom + # metric type. Setting this flag to "true" could cause extra Stackdriver + # charge. If metrics.backend-destination is not Stackdriver, this is + # ignored. metrics.allow-stackdriver-custom-metrics: "false" diff --git a/config/controller.yaml b/config/controller.yaml index ff25d78917b..1467af71944 100644 --- a/config/controller.yaml +++ b/config/controller.yaml @@ -16,6 +16,9 @@ kind: Deployment metadata: name: tekton-pipelines-controller namespace: tekton-pipelines + labels: + app.kubernetes.io/name: tekton-pipelines + app.kubernetes.io/component: controller spec: replicas: 1 template: @@ -24,6 +27,8 @@ spec: cluster-autoscaler.kubernetes.io/safe-to-evict: "false" labels: app: tekton-pipelines-controller + app.kubernetes.io/name: tekton-pipelines + app.kubernetes.io/component: controller spec: serviceAccountName: tekton-pipelines-controller containers: diff --git a/config/webhook.yaml b/config/webhook.yaml index 83aae6664ef..93a340930e8 100644 --- a/config/webhook.yaml +++ b/config/webhook.yaml @@ -17,6 +17,9 @@ kind: Deployment metadata: name: tekton-pipelines-webhook namespace: tekton-pipelines + labels: + app.kubernetes.io/name: tekton-pipelines + app.kubernetes.io/component: webhook-controller spec: replicas: 1 template: @@ -25,6 +28,8 @@ spec: cluster-autoscaler.kubernetes.io/safe-to-evict: "false" labels: app: tekton-pipelines-webhook + app.kubernetes.io/name: tekton-pipelines + app.kubernetes.io/component: webhook-controller spec: serviceAccountName: tekton-pipelines-controller containers: diff --git a/pkg/reconciler/taskrun/resources/pod.go b/pkg/reconciler/taskrun/resources/pod.go index 189af68616e..0017eeb5640 100644 --- a/pkg/reconciler/taskrun/resources/pod.go +++ b/pkg/reconciler/taskrun/resources/pod.go @@ -47,6 +47,10 @@ import ( const ( workspaceDir = "/workspace" homeDir = "/builder/home" + + taskRunLabelKey = pipeline.GroupName + pipeline.TaskRunLabelKey + ManagedByLabelKey = "app.kubernetes.io/managed-by" + ManagedByLabelValue = "tekton-pipelines" ) // These are effectively const, but Go doesn't have such an annotation. @@ -387,10 +391,18 @@ func IsContainerStep(name string) bool { // makeLabels constructs the labels we will propagate from TaskRuns to Pods. func makeLabels(s *v1alpha1.TaskRun) map[string]string { labels := make(map[string]string, len(s.ObjectMeta.Labels)+1) + // NB: Set this *before* passing through TaskRun labels. If the TaskRun + // has a managed-by label, it should override this default. + + // Copy through the TaskRun's labels to the underlying Pod's. + labels[ManagedByLabelKey] = ManagedByLabelValue for k, v := range s.ObjectMeta.Labels { labels[k] = v } - labels[pipeline.GroupName+pipeline.TaskRunLabelKey] = s.Name + + // NB: Set this *after* passing through TaskRun Labels. If the TaskRun + // specifies this label, it should be overridden by this value. + labels[taskRunLabelKey] = s.Name return labels } diff --git a/pkg/reconciler/taskrun/resources/pod_test.go b/pkg/reconciler/taskrun/resources/pod_test.go index 6b74f5e7941..d927e593ebe 100644 --- a/pkg/reconciler/taskrun/resources/pod_test.go +++ b/pkg/reconciler/taskrun/resources/pod_test.go @@ -119,12 +119,12 @@ func TestMakePod(t *testing.T) { defer func() { randReader = rand.Reader }() for _, c := range []struct { - desc string - trs v1alpha1.TaskRunSpec - ts v1alpha1.TaskSpec - bAnnotations map[string]string - want *corev1.PodSpec - wantErr error + desc string + trs v1alpha1.TaskRunSpec + ts v1alpha1.TaskSpec + annotations map[string]string + want *corev1.PodSpec + wantErr error }{{ desc: "simple", ts: v1alpha1.TaskSpec{ @@ -133,7 +133,7 @@ func TestMakePod(t *testing.T) { Image: "image", }}}, }, - bAnnotations: map[string]string{ + annotations: map[string]string{ "simple-annotation-key": "simple-annotation-val", }, want: &corev1.PodSpec{ @@ -215,7 +215,7 @@ func TestMakePod(t *testing.T) { Image: "image", }}}, }, - bAnnotations: map[string]string{ + annotations: map[string]string{ "simple-annotation-key": "simple-annotation-val", }, want: &corev1.PodSpec{ @@ -253,7 +253,7 @@ func TestMakePod(t *testing.T) { Image: "image", }}}, }, - bAnnotations: map[string]string{ + annotations: map[string]string{ "simple-annotation-key": "simple-annotation-val", }, want: &corev1.PodSpec{ @@ -403,7 +403,7 @@ func TestMakePod(t *testing.T) { tr := &v1alpha1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: "taskrun-name", - Annotations: c.bAnnotations, + Annotations: c.annotations, }, Spec: c.trs, } @@ -423,8 +423,8 @@ func TestMakePod(t *testing.T) { } wantAnnotations := map[string]string{ReadyAnnotation: ""} - if c.bAnnotations != nil { - for key, val := range c.bAnnotations { + if c.annotations != nil { + for key, val := range c.annotations { wantAnnotations[key] = val } } @@ -433,7 +433,51 @@ func TestMakePod(t *testing.T) { } }) } +} +func TestMakeLabels(t *testing.T) { + taskRunName := "task-run-name" + for _, c := range []struct { + desc string + trLabels map[string]string + want map[string]string + }{{ + desc: "taskrun labels pass through", + trLabels: map[string]string{ + "foo": "bar", + "hello": "world", + }, + want: map[string]string{ + taskRunLabelKey: taskRunName, + ManagedByLabelKey: ManagedByLabelValue, + "foo": "bar", + "hello": "world", + }, + }, { + desc: "taskrun managed-by overrides; taskrun label key doesn't", + trLabels: map[string]string{ + "foo": "bar", + taskRunLabelKey: "override-me", + ManagedByLabelKey: "managed-by-something-else", + }, + want: map[string]string{ + taskRunLabelKey: taskRunName, + ManagedByLabelKey: "managed-by-something-else", + "foo": "bar", + }, + }} { + t.Run(c.desc, func(t *testing.T) { + got := makeLabels(&v1alpha1.TaskRun{ + ObjectMeta: metav1.ObjectMeta{ + Name: taskRunName, + Labels: c.trLabels, + }, + }) + if d := cmp.Diff(got, c.want); d != "" { + t.Errorf("Diff labels:\n%s", d) + } + }) + } } func TestAddReadyAnnotation(t *testing.T) { @@ -528,7 +572,7 @@ func TestInitOutputResourcesDefaultDir(t *testing.T) { }}, }, } - bAnnotations := map[string]string{ + annotations := map[string]string{ "simple-annotation-key": "simple-annotation-val", } want := &corev1.PodSpec{ @@ -590,7 +634,7 @@ func TestInitOutputResourcesDefaultDir(t *testing.T) { tr := &v1alpha1.TaskRun{ ObjectMeta: metav1.ObjectMeta{ Name: "taskrun-name", - Annotations: bAnnotations, + Annotations: annotations, }, Spec: trs, } @@ -610,7 +654,7 @@ func TestInitOutputResourcesDefaultDir(t *testing.T) { } wantAnnotations := map[string]string{"simple-annotation-key": "simple-annotation-val", ReadyAnnotation: ""} - for key, val := range bAnnotations { + for key, val := range annotations { wantAnnotations[key] = val } if d := cmp.Diff(got.Annotations, wantAnnotations); d != "" { diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index d93a4b070d9..23e30297a8e 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -431,6 +431,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-run-success"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-run-success", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -462,6 +463,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-with-sa"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-sa-run-success"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-sa-run-success", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -494,6 +496,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-task-with-substitution"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-substitution"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-substitution", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -584,6 +587,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-output-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-input-output"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-input-output", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -716,6 +720,7 @@ func TestReconcile(t *testing.T) { wantPod: tb.Pod("test-taskrun-with-taskspec-pod-123456", "foo", tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-taskspec"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-taskspec", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -763,6 +768,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-cluster-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-cluster-task"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-cluster-task", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -793,6 +799,7 @@ func TestReconcile(t *testing.T) { wantPod: tb.Pod("test-taskrun-with-resource-spec-pod-123456", "foo", tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-resource-spec"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-resource-spec", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -841,6 +848,7 @@ func TestReconcile(t *testing.T) { tb.PodLabel("TaskRunLabel", "TaskRunValue"), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-labels"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-labels", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -873,6 +881,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("TaskRunAnnotation", "TaskRunValue"), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-annotations"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-annotations", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -904,6 +913,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-task-env"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-task-env"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-task-env", tb.OwnerReferenceAPIVersion("tekton.dev/v1alpha1")), tb.PodSpec( @@ -936,6 +946,7 @@ func TestReconcile(t *testing.T) { wantPod: tb.Pod("test-taskrun-with-resource-requests-pod-123456", "foo", tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-resource-requests"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-resource-requests", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec( @@ -1004,6 +1015,7 @@ func TestReconcile(t *testing.T) { tb.PodAnnotation("tekton.dev/ready", ""), tb.PodLabel(taskNameLabelKey, "test-task"), tb.PodLabel(taskRunNameLabelKey, "test-taskrun-with-pod"), + tb.PodLabel(resources.ManagedByLabelKey, resources.ManagedByLabelValue), tb.PodOwnerReference("TaskRun", "test-taskrun-with-pod", tb.OwnerReferenceAPIVersion(currentApiVersion)), tb.PodSpec(