From 8288e9a88df534fdf63f42d51b7652409434eda2 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Wed, 15 Dec 2021 09:18:08 +0100 Subject: [PATCH 1/7] Update: Refactoring Helm labels Signed-off-by: Nicolas Lamirault --- charts/karpenter/Chart.yaml | 2 +- .../templates/100-config-logging.yaml | 2 +- charts/karpenter/templates/_helpers.tpl | 68 +++++++++++++++++++ .../templates/controller/deployment.yaml | 8 ++- .../karpenter/templates/controller/rbac.yaml | 10 ++- .../karpenter/templates/serviceaccount.yaml | 4 +- .../templates/webhook/deployment.yaml | 11 ++- charts/karpenter/templates/webhook/rbac.yaml | 12 +++- .../karpenter/templates/webhook/webhooks.yaml | 6 ++ charts/karpenter/values.yaml | 4 ++ 10 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 charts/karpenter/templates/_helpers.tpl diff --git a/charts/karpenter/Chart.yaml b/charts/karpenter/Chart.yaml index 6e0f76c11b70..ebc674d3d543 100644 --- a/charts/karpenter/Chart.yaml +++ b/charts/karpenter/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v2 name: karpenter description: A Helm chart for https://github.com/aws/karpenter/. type: application -version: 0.5.2 +version: 0.5.3 diff --git a/charts/karpenter/templates/100-config-logging.yaml b/charts/karpenter/templates/100-config-logging.yaml index aa5d406bfadc..8361ff92c75a 100644 --- a/charts/karpenter/templates/100-config-logging.yaml +++ b/charts/karpenter/templates/100-config-logging.yaml @@ -4,7 +4,7 @@ metadata: name: config-logging namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/part-of: karpenter + {{- include "karpenter.labels" . | indent 4 }} data: # https://github.com/uber-go/zap/blob/aa3e73ec0896f8b066ddf668597a02f89628ee50/config.go zap-logger-config: | diff --git a/charts/karpenter/templates/_helpers.tpl b/charts/karpenter/templates/_helpers.tpl new file mode 100644 index 000000000000..d0f64b411b22 --- /dev/null +++ b/charts/karpenter/templates/_helpers.tpl @@ -0,0 +1,68 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "karpenter.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "karpenter.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "karpenter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Generate basic labels +*/}} +{{- define "karpenter.labels" }} +helm.sh/chart: {{ include "karpenter.chart" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +app.kubernetes.io/component: node-provisionning-controller +app.kubernetes.io/part-of: {{ template "karpenter.name" . }} +{{- include "karpenter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +{{- if .Values.additionalLabels }} +{{ toYaml .Values.additionalLabels }} +{{- end }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "karpenter.selectorLabels" }} +app.kubernetes.io/name: {{ include "karpenter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "karpenter.serviceAccountName" -}} +{{- if .Values.serviceAccount.enabled -}} + {{ default (include "karpenter.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/charts/karpenter/templates/controller/deployment.yaml b/charts/karpenter/templates/controller/deployment.yaml index e2c7c66f9ea1..f15fe8458e97 100644 --- a/charts/karpenter/templates/controller/deployment.yaml +++ b/charts/karpenter/templates/controller/deployment.yaml @@ -3,6 +3,8 @@ kind: Service metadata: name: karpenter-metrics namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} spec: ports: - port: 8080 @@ -15,6 +17,8 @@ kind: Deployment metadata: name: karpenter-controller namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} spec: replicas: {{ .Values.controller.replicas }} strategy: @@ -22,13 +26,15 @@ spec: selector: matchLabels: karpenter: controller + {{- include "karpenter.selectorLabels" . | indent 6 }} template: metadata: labels: karpenter: controller + {{- include "karpenter.labels" . | indent 8 }} spec: priorityClassName: system-cluster-critical - serviceAccountName: {{ .Values.serviceAccount.name }} + serviceAccountName: {{ template "karpenter.serviceAccountName" . }} containers: - name: manager image: {{ .Values.controller.image }} diff --git a/charts/karpenter/templates/controller/rbac.yaml b/charts/karpenter/templates/controller/rbac.yaml index 399e2e03db61..a5eb90f749e0 100644 --- a/charts/karpenter/templates/controller/rbac.yaml +++ b/charts/karpenter/templates/controller/rbac.yaml @@ -2,6 +2,8 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: karpenter-controller + labels: + {{- include "karpenter.labels" . | indent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -16,13 +18,15 @@ kind: RoleBinding metadata: name: karpenter-controller namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: karpenter-controller subjects: - kind: ServiceAccount - name: {{ .Values.serviceAccount.name }} + name: {{ template "karpenter.serviceAccountName" . }} namespace: {{ .Release.Namespace }} --- apiVersion: rbac.authorization.k8s.io/v1 @@ -30,6 +34,8 @@ kind: Role metadata: name: karpenter-controller namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} rules: - apiGroups: [""] resources: ["configmaps"] @@ -45,6 +51,8 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: karpenter-controller + labels: + {{- include "karpenter.labels" . | indent 4 }} rules: - apiGroups: ["karpenter.sh"] resources: ["provisioners", "provisioners/status"] diff --git a/charts/karpenter/templates/serviceaccount.yaml b/charts/karpenter/templates/serviceaccount.yaml index f1832b947ccf..5396153316fb 100644 --- a/charts/karpenter/templates/serviceaccount.yaml +++ b/charts/karpenter/templates/serviceaccount.yaml @@ -2,8 +2,10 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ .Values.serviceAccount.name }} + name: {{ template "karpenter.fullname" . }} namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/charts/karpenter/templates/webhook/deployment.yaml b/charts/karpenter/templates/webhook/deployment.yaml index 6533dc87b228..021ca745c96f 100644 --- a/charts/karpenter/templates/webhook/deployment.yaml +++ b/charts/karpenter/templates/webhook/deployment.yaml @@ -3,18 +3,23 @@ kind: Service metadata: name: karpenter-webhook namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} spec: ports: - port: 443 targetPort: webhook selector: karpenter: webhook + {{- include "karpenter.selectorLabels" . | indent 4 }} --- apiVersion: apps/v1 kind: Deployment metadata: name: karpenter-webhook namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} spec: replicas: {{ .Values.webhook.replicas }} strategy: @@ -22,13 +27,15 @@ spec: selector: matchLabels: karpenter: webhook + {{- include "karpenter.selectorLabels" . | indent 6 }} template: metadata: labels: karpenter: webhook + {{- include "karpenter.labels" . | indent 8 }} spec: priorityClassName: system-cluster-critical - serviceAccountName: {{ .Values.serviceAccount.name }} + serviceAccountName: {{ template "karpenter.serviceAccountName" . }} containers: - name: webhook image: {{ .Values.webhook.image }} @@ -95,4 +102,6 @@ kind: Secret metadata: name: karpenter-webhook-cert namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} data: {} # Injected by karpenter-webhook diff --git a/charts/karpenter/templates/webhook/rbac.yaml b/charts/karpenter/templates/webhook/rbac.yaml index 87bf0693fe40..2cb7e5c86e66 100644 --- a/charts/karpenter/templates/webhook/rbac.yaml +++ b/charts/karpenter/templates/webhook/rbac.yaml @@ -2,13 +2,15 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: karpenter-webhook + labels: + {{- include "karpenter.labels" . | indent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: karpenter-webhook subjects: - kind: ServiceAccount - name: {{ .Values.serviceAccount.name }} + name: {{ template "karpenter.serviceAccountName" . }} namespace: {{ .Release.Namespace }} --- apiVersion: rbac.authorization.k8s.io/v1 @@ -16,13 +18,15 @@ kind: RoleBinding metadata: name: karpenter-webhook namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: karpenter-webhook subjects: - kind: ServiceAccount - name: {{ .Values.serviceAccount.name }} + name: {{ template "karpenter.serviceAccountName" . }} namespace: {{ .Release.Namespace }} --- apiVersion: rbac.authorization.k8s.io/v1 @@ -30,6 +34,8 @@ kind: Role metadata: name: karpenter-webhook namespace: {{ .Release.Namespace }} + labels: + {{- include "karpenter.labels" . | indent 4 }} rules: - apiGroups: [""] resources: ["configmaps", "namespaces"] @@ -45,6 +51,8 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: karpenter-webhook + labels: + {{- include "karpenter.labels" . | indent 4 }} rules: - apiGroups: ["admissionregistration.k8s.io"] resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"] diff --git a/charts/karpenter/templates/webhook/webhooks.yaml b/charts/karpenter/templates/webhook/webhooks.yaml index 777efce733f2..f572161a18da 100644 --- a/charts/karpenter/templates/webhook/webhooks.yaml +++ b/charts/karpenter/templates/webhook/webhooks.yaml @@ -2,6 +2,8 @@ apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: name: defaulting.webhook.provisioners.karpenter.sh + labels: + {{- include "karpenter.labels" . | indent 4 }} webhooks: - admissionReviewVersions: ["v1"] clientConfig: @@ -27,6 +29,8 @@ apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validation.webhook.provisioners.karpenter.sh + labels: + {{- include "karpenter.labels" . | indent 4 }} webhooks: - admissionReviewVersions: ["v1"] clientConfig: @@ -52,6 +56,8 @@ apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: validation.webhook.config.karpenter.sh + labels: + {{- include "karpenter.labels" . | indent 4 }} webhooks: - admissionReviewVersions: ["v1"] clientConfig: diff --git a/charts/karpenter/values.yaml b/charts/karpenter/values.yaml index f068246ad1b2..a264d243ae94 100644 --- a/charts/karpenter/values.yaml +++ b/charts/karpenter/values.yaml @@ -1,3 +1,7 @@ +# -- Additional labels to add into metadata +additionalLabels: #{} + app: karpenter + serviceAccount: # -- Create a service account for the application controller create: true From 5460873657ba2b4e7e99a410384fd08399b5422f Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Wed, 15 Dec 2021 09:20:41 +0100 Subject: [PATCH 2/7] Update: empty additional labels by default Signed-off-by: Nicolas Lamirault --- charts/karpenter/values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/karpenter/values.yaml b/charts/karpenter/values.yaml index a264d243ae94..68b4e0550f6d 100644 --- a/charts/karpenter/values.yaml +++ b/charts/karpenter/values.yaml @@ -1,6 +1,6 @@ # -- Additional labels to add into metadata -additionalLabels: #{} - app: karpenter +additionalLabels: {} + # app: karpenter serviceAccount: # -- Create a service account for the application controller From 25260e2ffbfdbc09274bc91cb820d2efed2a31c8 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Wed, 15 Dec 2021 17:06:37 +0100 Subject: [PATCH 3/7] Fix: do not increasae Chart version Signed-off-by: Nicolas Lamirault --- charts/karpenter/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/karpenter/Chart.yaml b/charts/karpenter/Chart.yaml index ebc674d3d543..6e0f76c11b70 100644 --- a/charts/karpenter/Chart.yaml +++ b/charts/karpenter/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v2 name: karpenter description: A Helm chart for https://github.com/aws/karpenter/. type: application -version: 0.5.3 +version: 0.5.2 From 28b8e8c763e7a33989c8c0def798b24d419d2afd Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Wed, 15 Dec 2021 17:07:06 +0100 Subject: [PATCH 4/7] Fix: component name Signed-off-by: Nicolas Lamirault --- charts/karpenter/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/karpenter/templates/_helpers.tpl b/charts/karpenter/templates/_helpers.tpl index d0f64b411b22..a14e3c23ad3c 100644 --- a/charts/karpenter/templates/_helpers.tpl +++ b/charts/karpenter/templates/_helpers.tpl @@ -37,7 +37,7 @@ Generate basic labels {{- define "karpenter.labels" }} helm.sh/chart: {{ include "karpenter.chart" . }} app.kubernetes.io/managed-by: {{ .Release.Service }} -app.kubernetes.io/component: node-provisionning-controller +app.kubernetes.io/component: karpenter app.kubernetes.io/part-of: {{ template "karpenter.name" . }} {{- include "karpenter.selectorLabels" . }} {{- if .Chart.AppVersion }} From 3f7b99285f1aab252e139d8c3331a5a2d45aea66 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Wed, 15 Dec 2021 17:08:22 +0100 Subject: [PATCH 5/7] Fix: Chart version Signed-off-by: Nicolas Lamirault --- charts/karpenter/templates/_helpers.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/karpenter/templates/_helpers.tpl b/charts/karpenter/templates/_helpers.tpl index a14e3c23ad3c..54926e4f4b0b 100644 --- a/charts/karpenter/templates/_helpers.tpl +++ b/charts/karpenter/templates/_helpers.tpl @@ -40,8 +40,8 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/component: karpenter app.kubernetes.io/part-of: {{ template "karpenter.name" . }} {{- include "karpenter.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- if .Chart.Version }} +app.kubernetes.io/version: {{ .Chart.Version | quote }} {{- end }} {{- if .Values.additionalLabels }} {{ toYaml .Values.additionalLabels }} From 60538955dca92ab55d9e9e968fc474c4e26b28d1 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Tue, 21 Dec 2021 15:31:04 +0100 Subject: [PATCH 6/7] Fix: remove vim settings Signed-off-by: Nicolas Lamirault --- charts/karpenter/templates/_helpers.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/charts/karpenter/templates/_helpers.tpl b/charts/karpenter/templates/_helpers.tpl index 54926e4f4b0b..72bff8769c7b 100644 --- a/charts/karpenter/templates/_helpers.tpl +++ b/charts/karpenter/templates/_helpers.tpl @@ -1,4 +1,3 @@ -{{/* vim: set filetype=mustache: */}} {{/* Expand the name of the chart. */}} From abca99fbfde74377ce95720458268880f07f6dd9 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Wed, 5 Jan 2022 10:05:33 +0100 Subject: [PATCH 7/7] Fix: service account name Signed-off-by: Nicolas Lamirault --- charts/karpenter/templates/serviceaccount.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/karpenter/templates/serviceaccount.yaml b/charts/karpenter/templates/serviceaccount.yaml index 5396153316fb..aa2a1e001511 100644 --- a/charts/karpenter/templates/serviceaccount.yaml +++ b/charts/karpenter/templates/serviceaccount.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ template "karpenter.fullname" . }} + name: {{ include "karpenter.serviceAccountName" . }} namespace: {{ .Release.Namespace }} labels: {{- include "karpenter.labels" . | indent 4 }}