From 7854d5fc55fcafdd58a6fc1be6ce31ead7deb33f Mon Sep 17 00:00:00 2001 From: Marco Bebway Date: Tue, 5 Dec 2023 13:34:51 +0100 Subject: [PATCH] Use common labels for the NATS manager resources (#236) --- .../crd/bases/operator.kyma-project.io_nats.yaml | 1 + config/default/kustomization.yaml | 14 ++++++++++---- config/manager/manager.yaml | 9 +-------- config/manager/priority-class.yaml | 1 + config/rbac/role.yaml | 1 + config/rbac/role_binding.yaml | 8 +------- config/rbac/service_account.yaml | 8 +------- .../validation/integration_test.go | 3 --- pkg/manager/overrides_test.go | 10 ++++++++-- resources/nats/templates/_helpers.tpl | 1 - resources/nats/values.yaml | 7 ++++++- 11 files changed, 30 insertions(+), 33 deletions(-) diff --git a/config/crd/bases/operator.kyma-project.io_nats.yaml b/config/crd/bases/operator.kyma-project.io_nats.yaml index dc54fabb..4cc06168 100644 --- a/config/crd/bases/operator.kyma-project.io_nats.yaml +++ b/config/crd/bases/operator.kyma-project.io_nats.yaml @@ -6,6 +6,7 @@ metadata: controller-gen.kubebuilder.io/version: v0.11.1 creationTimestamp: null name: nats.operator.kyma-project.io + labels: {} spec: group: operator.kyma-project.io names: diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 515012c7..bf23708f 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -9,10 +9,16 @@ namespace: kyma-system namePrefix: nats- # Labels to add to all resources and selectors. -#labels: -#- includeSelectors: true -# pairs: -# someName: someValue +labels: + - includeSelectors: false + pairs: + app.kubernetes.io/component: nats-manager + app.kubernetes.io/created-by: nats-manager + app.kubernetes.io/instance: nats-manager + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/name: nats-manager + app.kubernetes.io/part-of: Kyma + control-plane: nats-manager resources: - ../crd diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index f9eb8fc7..ed3b6f37 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -3,14 +3,7 @@ kind: Deployment metadata: name: manager namespace: system - labels: - control-plane: manager - app.kubernetes.io/name: deployment - app.kubernetes.io/instance: manager - app.kubernetes.io/component: manager - app.kubernetes.io/created-by: nats-manager - app.kubernetes.io/part-of: nats-manager - app.kubernetes.io/managed-by: kustomize + labels: {} spec: selector: matchLabels: diff --git a/config/manager/priority-class.yaml b/config/manager/priority-class.yaml index a7d1b0e3..08e158b3 100644 --- a/config/manager/priority-class.yaml +++ b/config/manager/priority-class.yaml @@ -2,6 +2,7 @@ apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: manager-priority-class + labels: {} value: 2000000 globalDefault: false description: "Scheduling priority of the NATS-Manager module. Must not be blocked by unschedulable user workloads." diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index b4259cd7..d68e8473 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: creationTimestamp: null + labels: {} name: manager-role rules: - apiGroups: diff --git a/config/rbac/role_binding.yaml b/config/rbac/role_binding.yaml index fb992b8a..a814095b 100644 --- a/config/rbac/role_binding.yaml +++ b/config/rbac/role_binding.yaml @@ -1,13 +1,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - labels: - app.kubernetes.io/name: clusterrolebinding - app.kubernetes.io/instance: manager-rolebinding - app.kubernetes.io/component: rbac - app.kubernetes.io/created-by: nats-manager - app.kubernetes.io/part-of: nats-manager - app.kubernetes.io/managed-by: kustomize + labels: {} name: manager-rolebinding roleRef: apiGroup: rbac.authorization.k8s.io diff --git a/config/rbac/service_account.yaml b/config/rbac/service_account.yaml index 2ab8640b..ecf46663 100644 --- a/config/rbac/service_account.yaml +++ b/config/rbac/service_account.yaml @@ -1,12 +1,6 @@ apiVersion: v1 kind: ServiceAccount metadata: - labels: - app.kubernetes.io/name: serviceaccount - app.kubernetes.io/instance: manager-sa - app.kubernetes.io/component: rbac - app.kubernetes.io/created-by: nats-manager - app.kubernetes.io/part-of: nats-manager - app.kubernetes.io/managed-by: kustomize + labels: {} name: manager namespace: system diff --git a/internal/controller/nats/integrationtests/validation/integration_test.go b/internal/controller/nats/integrationtests/validation/integration_test.go index 1410a852..8749f06c 100644 --- a/internal/controller/nats/integrationtests/validation/integration_test.go +++ b/internal/controller/nats/integrationtests/validation/integration_test.go @@ -226,8 +226,6 @@ func Test_Validate_CreateNATS(t *testing.T) { // object in the K8s cluster, then tries to modify it with givenUpdates, and test the error that was caused by this // update, against a wantErrMsg. func Test_Validate_UpdateNATS(t *testing.T) { - t.Parallel() - testCases := []struct { name string givenNATS *v1alpha1.NATS @@ -303,7 +301,6 @@ func Test_Validate_UpdateNATS(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - t.Parallel() g := gomega.NewGomegaWithT(t) // given diff --git a/pkg/manager/overrides_test.go b/pkg/manager/overrides_test.go index 9775c0d4..fdf6999f 100644 --- a/pkg/manager/overrides_test.go +++ b/pkg/manager/overrides_test.go @@ -146,8 +146,14 @@ func Test_Overrides_Keys(t *testing.T) { ResourceRequestsMemKey: "64Mi", ResourceLimitsCPUKey: "500m", ResourceLimitsMemKey: "1Gi", - CommonLabelsKey: map[string]interface{}{}, - CommonAnnotationsKey: map[string]interface{}{}, + CommonLabelsKey: map[string]interface{}{ + "app.kubernetes.io/component": "nats-manager", + "app.kubernetes.io/created-by": "nats-manager", + "app.kubernetes.io/managed-by": "nats-manager", + "app.kubernetes.io/part-of": "nats-manager", + "control-plane": "nats-manager", + }, + CommonAnnotationsKey: map[string]interface{}{}, } // run test cases diff --git a/resources/nats/templates/_helpers.tpl b/resources/nats/templates/_helpers.tpl index f1d6cbab..e2355fd0 100644 --- a/resources/nats/templates/_helpers.tpl +++ b/resources/nats/templates/_helpers.tpl @@ -38,7 +38,6 @@ helm.sh/chart: {{ include "nats.chart" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} {{/* diff --git a/resources/nats/values.yaml b/resources/nats/values.yaml index 41011b89..3407d504 100644 --- a/resources/nats/values.yaml +++ b/resources/nats/values.yaml @@ -316,7 +316,12 @@ appProtocol: k8sClusterDomain: cluster.local # Add labels to all the deployed resources -commonLabels: {} +commonLabels: + app.kubernetes.io/component: nats-manager + app.kubernetes.io/created-by: nats-manager + app.kubernetes.io/managed-by: nats-manager + app.kubernetes.io/part-of: nats-manager + control-plane: nats-manager # Add annotations to all the deployed resources commonAnnotations: {}