From f9142b90e142bdb9b5bc6eb2bb41aa64f8a9b634 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Wed, 26 Jul 2023 15:16:28 +0530 Subject: [PATCH 1/3] Move labels to helpers.tpl Signed-off-by: Shubham Gupta --- charts/coredns/Chart.yaml | 2 +- charts/coredns/templates/_helpers.tpl | 29 +++++++++++++++++++ .../templates/clusterrole-autoscaler.yaml | 11 +------ charts/coredns/templates/clusterrole.yaml | 11 +------ .../clusterrolebinding-autoscaler.yaml | 11 +------ .../coredns/templates/clusterrolebinding.yaml | 11 +------ .../templates/configmap-autoscaler.yaml | 11 +------ charts/coredns/templates/configmap.yaml | 11 +------ .../templates/deployment-autoscaler.yaml | 13 +-------- charts/coredns/templates/deployment.yaml | 11 +------ charts/coredns/templates/hpa.yaml | 11 +------ .../templates/poddisruptionbudget.yaml | 11 +------ .../coredns/templates/podsecuritypolicy.yaml | 12 +------- charts/coredns/templates/service-metrics.yaml | 11 +------ charts/coredns/templates/service.yaml | 11 +------ .../templates/serviceaccount-autoscaler.yaml | 11 +------ charts/coredns/templates/serviceaccount.yaml | 11 +------ charts/coredns/templates/servicemonitor.yaml | 11 +------ 18 files changed, 46 insertions(+), 164 deletions(-) diff --git a/charts/coredns/Chart.yaml b/charts/coredns/Chart.yaml index 1172c19..ef31ebd 100644 --- a/charts/coredns/Chart.yaml +++ b/charts/coredns/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: coredns -version: 1.24.1 +version: 1.24.2 appVersion: 1.10.1 home: https://coredns.io icon: https://coredns.io/images/CoreDNS_Colour_Horizontal.png diff --git a/charts/coredns/templates/_helpers.tpl b/charts/coredns/templates/_helpers.tpl index 61732b3..9c50032 100644 --- a/charts/coredns/templates/_helpers.tpl +++ b/charts/coredns/templates/_helpers.tpl @@ -19,6 +19,35 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- end -}} {{- end -}} +{{/* +Common labels +*/}} +{{- define "coredns.labels" -}} +app.kubernetes.io/managed-by: {{ .Release.Service | quote }} +app.kubernetes.io/instance: {{ .Release.Name | quote }} +helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.isClusterService }} +k8s-app: {{ template "coredns.k8sapplabel" . }} +kubernetes.io/cluster-service: "true" +kubernetes.io/name: "CoreDNS" +{{- end }} +app.kubernetes.io/name: {{ template "coredns.name" . }} +{{- end -}} + +{{/* +Common labels with autoscaler +*/}} +{{- define "coredns.labels.autoscaler" -}} +app.kubernetes.io/managed-by: {{ .Release.Service | quote }} +app.kubernetes.io/instance: {{ .Release.Name | quote }} +helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" +{{- if .Values.isClusterService }} +k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler +kubernetes.io/cluster-service: "true" +kubernetes.io/name: "CoreDNS" +{{- end }} +app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler +{{- end -}} {{/* Allow k8s-app label to be overridden diff --git a/charts/coredns/templates/clusterrole-autoscaler.yaml b/charts/coredns/templates/clusterrole-autoscaler.yaml index 241cfac..9bf57d2 100644 --- a/charts/coredns/templates/clusterrole-autoscaler.yaml +++ b/charts/coredns/templates/clusterrole-autoscaler.yaml @@ -4,16 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: {{ template "coredns.fullname" . }}-autoscaler - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + labels: {{- include "coredns.labels.autoscaler" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/clusterrole.yaml b/charts/coredns/templates/clusterrole.yaml index 4f5c25b..c33762c 100644 --- a/charts/coredns/templates/clusterrole.yaml +++ b/charts/coredns/templates/clusterrole.yaml @@ -3,16 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: {{ template "coredns.fullname" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} rules: - apiGroups: - "" diff --git a/charts/coredns/templates/clusterrolebinding-autoscaler.yaml b/charts/coredns/templates/clusterrolebinding-autoscaler.yaml index 9c7a861..ef32306 100644 --- a/charts/coredns/templates/clusterrolebinding-autoscaler.yaml +++ b/charts/coredns/templates/clusterrolebinding-autoscaler.yaml @@ -4,16 +4,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: {{ template "coredns.fullname" . }}-autoscaler - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + labels: {{- include "coredns.labels.autoscaler" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/clusterrolebinding.yaml b/charts/coredns/templates/clusterrolebinding.yaml index 534a82d..36fa21c 100644 --- a/charts/coredns/templates/clusterrolebinding.yaml +++ b/charts/coredns/templates/clusterrolebinding.yaml @@ -3,16 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: {{ template "coredns.fullname" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/charts/coredns/templates/configmap-autoscaler.yaml b/charts/coredns/templates/configmap-autoscaler.yaml index dab4d5a..b10eb59 100644 --- a/charts/coredns/templates/configmap-autoscaler.yaml +++ b/charts/coredns/templates/configmap-autoscaler.yaml @@ -5,16 +5,7 @@ apiVersion: v1 metadata: name: {{ template "coredns.fullname" . }}-autoscaler namespace: {{ .Release.Namespace }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + labels: {{- include "coredns.labels.autoscaler" . | nindent 4 }} {{- if .Values.customLabels }} {{- toYaml .Values.customLabels | nindent 4 }} {{- end }} diff --git a/charts/coredns/templates/configmap.yaml b/charts/coredns/templates/configmap.yaml index 496f026..fe2a262 100644 --- a/charts/coredns/templates/configmap.yaml +++ b/charts/coredns/templates/configmap.yaml @@ -4,16 +4,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ template "coredns.fullname" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/deployment-autoscaler.yaml b/charts/coredns/templates/deployment-autoscaler.yaml index cb4e806..3cba866 100644 --- a/charts/coredns/templates/deployment-autoscaler.yaml +++ b/charts/coredns/templates/deployment-autoscaler.yaml @@ -5,18 +5,7 @@ kind: Deployment metadata: name: {{ template "coredns.fullname" . }}-autoscaler namespace: {{ .Release.Namespace }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - {{- if not (hasKey .Values.customLabels "k8s-app")}} - k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler - {{- end }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + labels: {{- include "coredns.labels.autoscaler" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/deployment.yaml b/charts/coredns/templates/deployment.yaml index ecbfec5..d607c4e 100644 --- a/charts/coredns/templates/deployment.yaml +++ b/charts/coredns/templates/deployment.yaml @@ -4,16 +4,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ default (include "coredns.fullname" .) .Values.deployment.name }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} diff --git a/charts/coredns/templates/hpa.yaml b/charts/coredns/templates/hpa.yaml index b0543b7..57a476b 100644 --- a/charts/coredns/templates/hpa.yaml +++ b/charts/coredns/templates/hpa.yaml @@ -8,16 +8,7 @@ apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: {{ template "coredns.fullname" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/poddisruptionbudget.yaml b/charts/coredns/templates/poddisruptionbudget.yaml index 5eddb35..272bc50 100644 --- a/charts/coredns/templates/poddisruptionbudget.yaml +++ b/charts/coredns/templates/poddisruptionbudget.yaml @@ -3,16 +3,7 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: {{ template "coredns.fullname" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/podsecuritypolicy.yaml b/charts/coredns/templates/podsecuritypolicy.yaml index de075fd..6e02e00 100644 --- a/charts/coredns/templates/podsecuritypolicy.yaml +++ b/charts/coredns/templates/podsecuritypolicy.yaml @@ -7,17 +7,7 @@ apiVersion: extensions/v1beta1 kind: PodSecurityPolicy metadata: name: {{ template "coredns.fullname" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- else }} - app.kubernetes.io/name: {{ template "coredns.name" . }} - {{- end }} + labels: {{- include "coredns.labels" . | nindent 4 }} spec: privileged: false # Required to prevent escalations to root. diff --git a/charts/coredns/templates/service-metrics.yaml b/charts/coredns/templates/service-metrics.yaml index 7e6ce78..42dadbb 100644 --- a/charts/coredns/templates/service-metrics.yaml +++ b/charts/coredns/templates/service-metrics.yaml @@ -3,16 +3,7 @@ apiVersion: v1 kind: Service metadata: name: {{ template "coredns.fullname" . }}-metrics - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} app.kubernetes.io/component: metrics {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} diff --git a/charts/coredns/templates/service.yaml b/charts/coredns/templates/service.yaml index efb4a60..7bd5c80 100644 --- a/charts/coredns/templates/service.yaml +++ b/charts/coredns/templates/service.yaml @@ -4,16 +4,7 @@ apiVersion: v1 kind: Service metadata: name: {{ default (include "coredns.fullname" .) .Values.service.name }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/serviceaccount-autoscaler.yaml b/charts/coredns/templates/serviceaccount-autoscaler.yaml index d068a03..8b0e9c7 100644 --- a/charts/coredns/templates/serviceaccount-autoscaler.yaml +++ b/charts/coredns/templates/serviceaccount-autoscaler.yaml @@ -5,16 +5,7 @@ kind: ServiceAccount metadata: name: {{ template "coredns.fullname" . }}-autoscaler namespace: {{ .Release.Namespace }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler + labels: {{- include "coredns.labels.autoscaler" . | nindent 4 }} {{- if .Values.customLabels }} {{ toYaml .Values.customLabels | indent 4 }} {{- end }} diff --git a/charts/coredns/templates/serviceaccount.yaml b/charts/coredns/templates/serviceaccount.yaml index 9cb4b03..7211676 100644 --- a/charts/coredns/templates/serviceaccount.yaml +++ b/charts/coredns/templates/serviceaccount.yaml @@ -3,16 +3,7 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ template "coredns.serviceAccountName" . }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} {{- if or .Values.serviceAccount.annotations .Values.customAnnotations }} annotations: {{- if .Values.customAnnotations }} diff --git a/charts/coredns/templates/servicemonitor.yaml b/charts/coredns/templates/servicemonitor.yaml index d5e6804..1c8fa27 100644 --- a/charts/coredns/templates/servicemonitor.yaml +++ b/charts/coredns/templates/servicemonitor.yaml @@ -6,16 +6,7 @@ metadata: {{- if .Values.prometheus.monitor.namespace }} namespace: {{ .Values.prometheus.monitor.namespace }} {{- end }} - labels: - app.kubernetes.io/managed-by: {{ .Release.Service | quote }} - app.kubernetes.io/instance: {{ .Release.Name | quote }} - helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - {{- if .Values.isClusterService }} - k8s-app: {{ template "coredns.k8sapplabel" . }} - kubernetes.io/cluster-service: "true" - kubernetes.io/name: "CoreDNS" - {{- end }} - app.kubernetes.io/name: {{ template "coredns.name" . }} + labels: {{- include "coredns.labels" . | nindent 4 }} {{- if .Values.prometheus.monitor.additionalLabels }} {{ toYaml .Values.prometheus.monitor.additionalLabels | indent 4 }} {{- end }} From d46048d352fd4d345653438b8dc397d6ba6cfac2 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Wed, 26 Jul 2023 15:21:21 +0530 Subject: [PATCH 2/3] change logs Signed-off-by: Shubham Gupta --- charts/coredns/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/coredns/Chart.yaml b/charts/coredns/Chart.yaml index ef31ebd..b3b0ed4 100644 --- a/charts/coredns/Chart.yaml +++ b/charts/coredns/Chart.yaml @@ -19,5 +19,5 @@ engine: gotpl type: application annotations: artifacthub.io/changes: | - - kind: added - description: Added autoscaler podAnnotations + - kind: Refacotring + description: Moved the labels from the the resource to a single helpers.tpl for better readability From b3644c95ca4f077c17c14809f4b843cc029b5fc0 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Wed, 26 Jul 2023 15:24:07 +0530 Subject: [PATCH 3/3] typo Signed-off-by: Shubham Gupta --- charts/coredns/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/coredns/Chart.yaml b/charts/coredns/Chart.yaml index b3b0ed4..4c46519 100644 --- a/charts/coredns/Chart.yaml +++ b/charts/coredns/Chart.yaml @@ -19,5 +19,5 @@ engine: gotpl type: application annotations: artifacthub.io/changes: | - - kind: Refacotring + - kind: Refactoring description: Moved the labels from the the resource to a single helpers.tpl for better readability