From 7112599a4371b10aaee42bb16463b5c94e51b154 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Fri, 7 Jun 2024 22:10:28 +0200 Subject: [PATCH 1/4] Allow overriding of selectors for Deployment, Services, PodDisruptionBudget and ServiceMonitor. This allows adapting to non-standard setups like for example AWS EKS CoreDNS Add-on, which use different labels and selectors. Signed-off-by: Alexander Berger --- charts/coredns/Chart.yaml | 4 ++-- charts/coredns/README.md | 4 ++++ charts/coredns/templates/deployment.yaml | 4 ++++ charts/coredns/templates/poddisruptionbudget.yaml | 2 ++ charts/coredns/templates/service-metrics.yaml | 4 ++++ charts/coredns/templates/service.yaml | 4 ++++ charts/coredns/templates/servicemonitor.yaml | 4 ++++ charts/coredns/values.yaml | 6 ++++++ 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/charts/coredns/Chart.yaml b/charts/coredns/Chart.yaml index be84a05..d4eb52c 100644 --- a/charts/coredns/Chart.yaml +++ b/charts/coredns/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: coredns -version: 1.30.0 +version: 1.30.1 appVersion: 1.11.1 home: https://coredns.io icon: https://coredns.io/images/CoreDNS_Colour_Horizontal.png @@ -20,4 +20,4 @@ type: application annotations: artifacthub.io/changes: | - kind: added - description: Ability to skip configmap management + description: Allow overriding the selectors for Deployment, Services, PodDisruptionBudget and ServiceMonitor diff --git a/charts/coredns/README.md b/charts/coredns/README.md index b98c4a2..75f3c2f 100644 --- a/charts/coredns/README.md +++ b/charts/coredns/README.md @@ -60,10 +60,12 @@ The command removes all the Kubernetes components associated with the chart and | `serviceType` | Kubernetes Service type | `ClusterIP` | | `prometheus.service.enabled` | Set this to `true` to create Service for Prometheus metrics | `false` | | `prometheus.service.annotations` | Annotations to add to the metrics Service | `{prometheus.io/scrape: "true", prometheus.io/port: "9153"}` | +| `prometheus.service.selector` | Pod selector | `{}` | | `prometheus.monitor.enabled` | Set this to `true` to create ServiceMonitor for Prometheus operator | `false` | | `prometheus.monitor.additionalLabels` | Additional labels that can be used so ServiceMonitor will be discovered by Prometheus | {} | | `prometheus.monitor.namespace` | Selector to select which namespaces the Endpoints objects are discovered from. | `""` | | `prometheus.monitor.interval` | Scrape interval for polling the metrics endpoint. (E.g. "30s") | `""` | +| `prometheus.monitor.selector` | Service selector | `{}` | | `service.clusterIP` | IP address to assign to service | `""` | | `service.clusterIPs` | IP addresses to assign to service | `[]` | | `service.loadBalancerIP` | IP address to assign to load balancer (if supported) | `""` | @@ -71,6 +73,7 @@ The command removes all the Kubernetes components associated with the chart and | `service.externalTrafficPolicy` | Enable client source IP preservation | [] | | `service.ipFamilyPolicy` | Service dual-stack policy | `""` | | `service.annotations` | Annotations to add to service | {} | +| `service.selector` | Pod selector | `{}` | | `serviceAccount.create` | If true, create & use serviceAccount | false | | `serviceAccount.name` | If not set & create is true, use template fullname | | | `rbac.create` | If true, create & use RBAC resources | true | @@ -141,6 +144,7 @@ The command removes all the Kubernetes components associated with the chart and | `deployment.enabled` | Optionally disable the main deployment and its respective resources. | `true` | | `deployment.name` | Name of the deployment if `deployment.enabled` is true. Otherwise the name of an existing deployment for the autoscaler or HPA to target. | `""` | | `deployment.annotations` | Annotations to add to the main deployment | `{}` | +| `deployment.selector` | Pod selector | `{}` | See `values.yaml` for configuration notes. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, diff --git a/charts/coredns/templates/deployment.yaml b/charts/coredns/templates/deployment.yaml index 1b3f86f..86db59f 100644 --- a/charts/coredns/templates/deployment.yaml +++ b/charts/coredns/templates/deployment.yaml @@ -29,12 +29,16 @@ spec: maxUnavailable: {{ .Values.rollingUpdate.maxUnavailable }} maxSurge: {{ .Values.rollingUpdate.maxSurge }} selector: + {{- if .Values.deployment.selector }} + {{- toYaml .Values.deployment.selector | nindent 4 }} + {{- else }} matchLabels: app.kubernetes.io/instance: {{ .Release.Name | quote }} {{- if .Values.isClusterService }} k8s-app: {{ template "coredns.k8sapplabel" . }} {{- end }} app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- end }} template: metadata: labels: diff --git a/charts/coredns/templates/poddisruptionbudget.yaml b/charts/coredns/templates/poddisruptionbudget.yaml index 9cc62c1..136d804 100644 --- a/charts/coredns/templates/poddisruptionbudget.yaml +++ b/charts/coredns/templates/poddisruptionbudget.yaml @@ -13,6 +13,7 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} spec: + {{- if not .Values.podDisruptionBudget.selector }} selector: matchLabels: app.kubernetes.io/instance: {{ .Release.Name | quote }} @@ -20,5 +21,6 @@ spec: k8s-app: {{ template "coredns.k8sapplabel" . }} {{- end }} app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- end }} {{ toYaml .Values.podDisruptionBudget | indent 2 }} {{- end }} diff --git a/charts/coredns/templates/service-metrics.yaml b/charts/coredns/templates/service-metrics.yaml index 1fc7b2d..0ae9a15 100644 --- a/charts/coredns/templates/service-metrics.yaml +++ b/charts/coredns/templates/service-metrics.yaml @@ -23,11 +23,15 @@ metadata: {{- end }} spec: selector: + {{- if .Values.prometheus.service.selector }} + {{- toYaml .Values.prometheus.service.selector | nindent 4 }} + {{- else }} app.kubernetes.io/instance: {{ .Release.Name | quote }} {{- if .Values.isClusterService }} k8s-app: {{ template "coredns.k8sapplabel" . }} {{- end }} app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- end }} ports: - name: metrics port: 9153 diff --git a/charts/coredns/templates/service.yaml b/charts/coredns/templates/service.yaml index e9c5b96..95babce 100644 --- a/charts/coredns/templates/service.yaml +++ b/charts/coredns/templates/service.yaml @@ -20,11 +20,15 @@ metadata: {{- end }} spec: selector: + {{- if .Values.service.selector }} + {{- toYaml .Values.service.selector | nindent 4 }} + {{- else }} app.kubernetes.io/instance: {{ .Release.Name | quote }} {{- if .Values.isClusterService }} k8s-app: {{ template "coredns.k8sapplabel" . }} {{- end }} app.kubernetes.io/name: {{ template "coredns.name" . }} + {{- end }} {{- if .Values.service.clusterIP }} clusterIP: {{ .Values.service.clusterIP }} {{- end }} diff --git a/charts/coredns/templates/servicemonitor.yaml b/charts/coredns/templates/servicemonitor.yaml index b5fc642..53f8bdb 100644 --- a/charts/coredns/templates/servicemonitor.yaml +++ b/charts/coredns/templates/servicemonitor.yaml @@ -21,6 +21,9 @@ spec: - {{ .Release.Namespace }} {{- end }} selector: + {{- if .Values.prometheus.monitor.selector }} + {{- toYaml .Values.prometheus.monitor.selector | nindent 4 }} + {{- else }} matchLabels: app.kubernetes.io/instance: {{ .Release.Name | quote }} {{- if .Values.isClusterService }} @@ -28,6 +31,7 @@ spec: {{- end }} app.kubernetes.io/name: {{ template "coredns.name" . }} app.kubernetes.io/component: metrics + {{- end }} endpoints: - port: metrics {{- if .Values.prometheus.monitor.interval }} diff --git a/charts/coredns/values.yaml b/charts/coredns/values.yaml index aa9ec71..85e24ad 100644 --- a/charts/coredns/values.yaml +++ b/charts/coredns/values.yaml @@ -42,11 +42,13 @@ prometheus: annotations: prometheus.io/scrape: "true" prometheus.io/port: "9153" + selector: {} monitor: enabled: false additionalLabels: {} namespace: "" interval: "" + selector: {} service: # clusterIP: "" @@ -59,6 +61,8 @@ service: # If not set, a name is generated using the fullname template name: "" annotations: {} + # Pod selector + selector: {} serviceAccount: create: false @@ -377,3 +381,5 @@ deployment: name: "" ## Annotations for the coredns deployment annotations: {} + ## Pod selector + selector: {} From e493b0dbd3ae00b5e56c72bcb7a8bda9ec69df70 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Fri, 7 Jun 2024 22:10:57 +0200 Subject: [PATCH 2/4] Allow overriding the ClusterRole and ClusterRoleBinding name. This allows adapting to non-standard setups like for example AWS EKS CoreDNS Add-on, which use different names. Signed-off-by: Alexander Berger --- charts/coredns/Chart.yaml | 2 ++ charts/coredns/README.md | 1 + charts/coredns/templates/_helpers.tpl | 11 +++++++++++ charts/coredns/templates/clusterrole.yaml | 2 +- charts/coredns/templates/clusterrolebinding.yaml | 4 ++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/charts/coredns/Chart.yaml b/charts/coredns/Chart.yaml index d4eb52c..c9bb2ca 100644 --- a/charts/coredns/Chart.yaml +++ b/charts/coredns/Chart.yaml @@ -21,3 +21,5 @@ annotations: artifacthub.io/changes: | - kind: added description: Allow overriding the selectors for Deployment, Services, PodDisruptionBudget and ServiceMonitor + - kind: added + description: Setting `clusterRole.nameOverride` to allow overriding the ClusterRole name. diff --git a/charts/coredns/README.md b/charts/coredns/README.md index 75f3c2f..43e15fe 100644 --- a/charts/coredns/README.md +++ b/charts/coredns/README.md @@ -145,6 +145,7 @@ The command removes all the Kubernetes components associated with the chart and | `deployment.name` | Name of the deployment if `deployment.enabled` is true. Otherwise the name of an existing deployment for the autoscaler or HPA to target. | `""` | | `deployment.annotations` | Annotations to add to the main deployment | `{}` | | `deployment.selector` | Pod selector | `{}` | +| `clusterRole.nameOverride` | ClusterRole name override | | See `values.yaml` for configuration notes. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, diff --git a/charts/coredns/templates/_helpers.tpl b/charts/coredns/templates/_helpers.tpl index 6dc6833..e6f7491 100644 --- a/charts/coredns/templates/_helpers.tpl +++ b/charts/coredns/templates/_helpers.tpl @@ -224,3 +224,14 @@ Create the name of the service account to use {{ default "default" .Values.serviceAccount.name }} {{- end -}} {{- end -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "coredns.clusterRoleName" -}} +{{- if and .Values.clusterRole .Values.clusterRole.nameOverride -}} + {{ .Values.clusterRole.nameOverride }} +{{- else -}} + {{ template "coredns.fullname" . }} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/coredns/templates/clusterrole.yaml b/charts/coredns/templates/clusterrole.yaml index c33762c..ecdeafa 100644 --- a/charts/coredns/templates/clusterrole.yaml +++ b/charts/coredns/templates/clusterrole.yaml @@ -2,7 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: {{ template "coredns.fullname" . }} + name: {{ template "coredns.clusterRoleName" . }} labels: {{- include "coredns.labels" . | nindent 4 }} rules: - apiGroups: diff --git a/charts/coredns/templates/clusterrolebinding.yaml b/charts/coredns/templates/clusterrolebinding.yaml index 36fa21c..ebeaf14 100644 --- a/charts/coredns/templates/clusterrolebinding.yaml +++ b/charts/coredns/templates/clusterrolebinding.yaml @@ -2,12 +2,12 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: - name: {{ template "coredns.fullname" . }} + name: {{ template "coredns.clusterRoleName" . }} labels: {{- include "coredns.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: {{ template "coredns.fullname" . }} + name: {{ template "coredns.clusterRoleName" . }} subjects: - kind: ServiceAccount name: {{ template "coredns.serviceAccountName" . }} From 294222f6c1e51e70574f1414234c9f3f406dd791 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Fri, 7 Jun 2024 22:10:57 +0200 Subject: [PATCH 3/4] Fix spacing to make linter happy Signed-off-by: Alexander Berger --- charts/coredns/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/coredns/values.yaml b/charts/coredns/values.yaml index 85e24ad..2c472c6 100644 --- a/charts/coredns/values.yaml +++ b/charts/coredns/values.yaml @@ -381,5 +381,5 @@ deployment: name: "" ## Annotations for the coredns deployment annotations: {} - ## Pod selector + ## Pod selector selector: {} From 0185693e63d52cfbc09d8cdef359a3b8464db7e8 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Thu, 13 Jun 2024 11:20:09 +0200 Subject: [PATCH 4/4] Upgrade chart minor version (instead of patch version) Signed-off-by: Alexander Berger --- 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 c9bb2ca..20d34aa 100644 --- a/charts/coredns/Chart.yaml +++ b/charts/coredns/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: coredns -version: 1.30.1 +version: 1.31.0 appVersion: 1.11.1 home: https://coredns.io icon: https://coredns.io/images/CoreDNS_Colour_Horizontal.png