From 767f1fb29a3a1f12f27abb2aa08206d7c944c402 Mon Sep 17 00:00:00 2001 From: Luna Stadler Date: Mon, 25 Mar 2024 15:41:30 +0100 Subject: [PATCH] [operator] Allow custom labels and annotations (#1067) * [operator] Add the ability to add `additionalLabels` This already existed in the `opentelemetry-collector` chart, now it is available in the `opentelemetry-operator` as well. These labels can be useful in environments where additional labels are recommended or required. * [operator] Allow adding custom annotations to various objects Similar to `additionalLabels`, but for annotations. This is somewhat inspired by `cert-manager`s Helm chart [1], which allows custom annotations on essentially all Kubernetes objects. E.g. there could be internal annotations in certain environments that are recommended or required [1]: https://artifacthub.io/packages/helm/cert-manager/cert-manager * [operator] Bump chart version for custom labels and annotations support --- charts/opentelemetry-operator/Chart.yaml | 2 +- .../operator-webhook-with-cert-manager.yaml | 6 ++- .../default/rendered/certmanager.yaml | 6 ++- .../default/rendered/clusterrole.yaml | 9 +++-- .../default/rendered/clusterrolebinding.yaml | 6 ++- .../examples/default/rendered/deployment.yaml | 3 +- .../examples/default/rendered/role.yaml | 3 +- .../default/rendered/rolebinding.yaml | 3 +- .../examples/default/rendered/service.yaml | 6 ++- .../default/rendered/serviceaccount.yaml | 3 +- .../tests/test-certmanager-connection.yaml | 3 +- .../tests/test-service-connection.yaml | 6 ++- .../templates/_helpers.tpl | 7 ++++ .../templates/deployment.yaml | 4 ++ .../templates/service.yaml | 8 ++++ .../opentelemetry-operator/values.schema.json | 38 ++++++++++++++++++- charts/opentelemetry-operator/values.yaml | 11 ++++++ 17 files changed, 104 insertions(+), 20 deletions(-) diff --git a/charts/opentelemetry-operator/Chart.yaml b/charts/opentelemetry-operator/Chart.yaml index ec344bd74..993935e52 100644 --- a/charts/opentelemetry-operator/Chart.yaml +++ b/charts/opentelemetry-operator/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: opentelemetry-operator -version: 0.52.0 +version: 0.52.1 description: OpenTelemetry Operator Helm chart for Kubernetes type: application home: https://opentelemetry.io/ diff --git a/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml b/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml index 62651b326..3d8328d9c 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/admission-webhooks/operator-webhook-with-cert-manager.yaml @@ -6,11 +6,12 @@ metadata: annotations: cert-manager.io/inject-ca-from: default/example-opentelemetry-operator-serving-cert labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: webhook name: example-opentelemetry-operator-mutation webhooks: @@ -90,11 +91,12 @@ metadata: annotations: cert-manager.io/inject-ca-from: default/example-opentelemetry-operator-serving-cert labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: webhook name: example-opentelemetry-operator-validation webhooks: diff --git a/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml b/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml index 79c9289f7..82dff3bd4 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/certmanager.yaml @@ -4,11 +4,12 @@ apiVersion: cert-manager.io/v1 kind: Certificate metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: webhook name: example-opentelemetry-operator-serving-cert namespace: default @@ -29,11 +30,12 @@ apiVersion: cert-manager.io/v1 kind: Issuer metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: webhook name: example-opentelemetry-operator-selfsigned-issuer namespace: default diff --git a/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml b/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml index 6c821e3cb..a7189d5b0 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/clusterrole.yaml @@ -4,11 +4,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-manager rules: @@ -213,11 +214,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-metrics rules: @@ -231,11 +233,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-proxy rules: diff --git a/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml b/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml index 33540e329..22423ec69 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/clusterrolebinding.yaml @@ -4,11 +4,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-manager roleRef: @@ -25,11 +26,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-proxy roleRef: diff --git a/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml b/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml index bafb7c8f5..af289fdc7 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/deployment.yaml @@ -4,11 +4,12 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator namespace: default diff --git a/charts/opentelemetry-operator/examples/default/rendered/role.yaml b/charts/opentelemetry-operator/examples/default/rendered/role.yaml index 837b3fb8b..5d1fa169d 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/role.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/role.yaml @@ -4,11 +4,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-leader-election namespace: default diff --git a/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml b/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml index c6044f639..825772736 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/rolebinding.yaml @@ -4,11 +4,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-leader-election namespace: default diff --git a/charts/opentelemetry-operator/examples/default/rendered/service.yaml b/charts/opentelemetry-operator/examples/default/rendered/service.yaml index f449d35d2..1f8903b29 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/service.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/service.yaml @@ -4,11 +4,12 @@ apiVersion: v1 kind: Service metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator namespace: default @@ -31,11 +32,12 @@ apiVersion: v1 kind: Service metadata: labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager name: example-opentelemetry-operator-webhook namespace: default diff --git a/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml b/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml index 720da7aae..badf1d39f 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/serviceaccount.yaml @@ -6,9 +6,10 @@ metadata: name: opentelemetry-operator namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager diff --git a/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml b/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml index c27a6b253..68feaedc6 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/tests/test-certmanager-connection.yaml @@ -6,11 +6,12 @@ metadata: name: "example-opentelemetry-operator-cert-manager" namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: webhook annotations: "helm.sh/hook": test diff --git a/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml b/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml index cda337ea3..da11a9021 100644 --- a/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml +++ b/charts/opentelemetry-operator/examples/default/rendered/tests/test-service-connection.yaml @@ -6,11 +6,12 @@ metadata: name: "example-opentelemetry-operator-metrics" namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager annotations: "helm.sh/hook": test @@ -43,11 +44,12 @@ metadata: name: "example-opentelemetry-operator-webhook" namespace: default labels: - helm.sh/chart: opentelemetry-operator-0.52.0 + helm.sh/chart: opentelemetry-operator-0.52.1 app.kubernetes.io/name: opentelemetry-operator app.kubernetes.io/version: "0.96.0" app.kubernetes.io/managed-by: Helm app.kubernetes.io/instance: example + app.kubernetes.io/component: controller-manager annotations: "helm.sh/hook": test diff --git a/charts/opentelemetry-operator/templates/_helpers.tpl b/charts/opentelemetry-operator/templates/_helpers.tpl index 8e84476cf..f78b0d8b3 100644 --- a/charts/opentelemetry-operator/templates/_helpers.tpl +++ b/charts/opentelemetry-operator/templates/_helpers.tpl @@ -41,6 +41,7 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} +{{ include "opentelemetry-operator.additionalLabels" . }} {{- end }} {{/* @@ -73,6 +74,12 @@ Create the name of the service account to use {{- end }} {{- end }} +{{- define "opentelemetry-operator.additionalLabels" -}} +{{- if .Values.additionalLabels }} +{{- tpl (.Values.additionalLabels | toYaml) . }} +{{- end }} +{{- end }} + {{/* Create an ordered name of the MutatingWebhookConfiguration */}} diff --git a/charts/opentelemetry-operator/templates/deployment.yaml b/charts/opentelemetry-operator/templates/deployment.yaml index 59810330d..393593b0d 100644 --- a/charts/opentelemetry-operator/templates/deployment.yaml +++ b/charts/opentelemetry-operator/templates/deployment.yaml @@ -1,6 +1,10 @@ apiVersion: apps/v1 kind: Deployment metadata: + {{- with .Values.manager.deploymentAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} labels: {{- include "opentelemetry-operator.labels" . | nindent 4 }} app.kubernetes.io/component: controller-manager diff --git a/charts/opentelemetry-operator/templates/service.yaml b/charts/opentelemetry-operator/templates/service.yaml index b523c35fe..d41b53aa7 100644 --- a/charts/opentelemetry-operator/templates/service.yaml +++ b/charts/opentelemetry-operator/templates/service.yaml @@ -1,6 +1,10 @@ apiVersion: v1 kind: Service metadata: + {{- with .Values.manager.serviceAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} labels: {{- include "opentelemetry-operator.labels" . | nindent 4 }} app.kubernetes.io/component: controller-manager @@ -27,6 +31,10 @@ spec: apiVersion: v1 kind: Service metadata: + {{- with .Values.admissionWebhooks.serviceAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} labels: {{- include "opentelemetry-operator.labels" . | nindent 4 }} app.kubernetes.io/component: controller-manager diff --git a/charts/opentelemetry-operator/values.schema.json b/charts/opentelemetry-operator/values.schema.json index 822bbe174..cf6e14c38 100644 --- a/charts/opentelemetry-operator/values.schema.json +++ b/charts/opentelemetry-operator/values.schema.json @@ -22,7 +22,8 @@ "hostNetwork", "priorityClassName", "securityContext", - "testFramework" + "testFramework", + "additionalLabels" ], "additionalProperties": false, "properties": { @@ -125,6 +126,8 @@ "env", "serviceAccount", "serviceMonitor", + "deploymentAnnotations", + "serviceAnnotations", "podAnnotations", "podLabels", "prometheusRule", @@ -726,6 +729,22 @@ }] }] }, + "deploymentAnnotations": { + "type": "object", + "default": {}, + "title": "The deploymentAnnotations Schema", + "required": [], + "properties": {}, + "examples": [{}] + }, + "serviceAnnotations": { + "type": "object", + "default": {}, + "title": "The serviceAnnotations Schema", + "required": [], + "properties": {}, + "examples": [{}] + }, "podAnnotations": { "type": "object", "default": {}, @@ -1275,6 +1294,7 @@ "cert_file", "key_file", "ca_file", + "serviceAnnotations", "secretAnnotations", "secretLabels" ], @@ -1474,6 +1494,14 @@ "" ] }, + "serviceAnnotations": { + "type": "object", + "default": {}, + "title": "The serviceAnnotations Schema", + "required": [], + "properties": {}, + "examples": [{}] + }, "secretAnnotations": { "type": "object", "default": {}, @@ -1713,6 +1741,14 @@ "tag": "latest" } }] + }, + "additionalLabels": { + "type": "object", + "default": {}, + "title": "The additionalLabels Schema", + "required": [], + "properties": {}, + "examples": [{}] } }, "examples": [{ diff --git a/charts/opentelemetry-operator/values.yaml b/charts/opentelemetry-operator/values.yaml index ed05f94a9..eb57b5169 100644 --- a/charts/opentelemetry-operator/values.yaml +++ b/charts/opentelemetry-operator/values.yaml @@ -14,6 +14,9 @@ imagePullSecrets: [] ## Kubernetes cluster domain suffix clusterDomain: cluster.local +# Common labels to add to all otel-operator resources. Evaluated as a template. +additionalLabels: {} + ## Pod Disruption Budget configuration ## pdb: @@ -97,6 +100,11 @@ manager: metricsEndpoints: - port: metrics + # Adds additional annotations to the manager Deployment + deploymentAnnotations: {} + # Adds additional annotations to the manager Service + serviceAnnotations: {} + podAnnotations: {} podLabels: {} @@ -239,6 +247,9 @@ admissionWebhooks: ## Path to the CA cert. ca_file: "" + # Adds additional annotations to the admissionWebhook Service + serviceAnnotations: {} + ## Secret annotations secretAnnotations: {} ## Secret labels