Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Helm labels #1001

Merged
merged 7 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/karpenter/templates/100-config-logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: config-logging
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/part-of: karpenter
bwagner5 marked this conversation as resolved.
Show resolved Hide resolved
{{- include "karpenter.labels" . | indent 4 }}
data:
# https://github.com/uber-go/zap/blob/aa3e73ec0896f8b066ddf668597a02f89628ee50/config.go
zap-logger-config: |
Expand Down
67 changes: 67 additions & 0 deletions charts/karpenter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{/*
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: karpenter
app.kubernetes.io/part-of: {{ template "karpenter.name" . }}
{{- include "karpenter.selectorLabels" . }}
{{- if .Chart.Version }}
app.kubernetes.io/version: {{ .Chart.Version | 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 -}}
8 changes: 7 additions & 1 deletion charts/karpenter/templates/controller/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: Service
metadata:
name: karpenter-metrics
namespace: {{ .Release.Namespace }}
labels:
{{- include "karpenter.labels" . | indent 4 }}
spec:
ports:
- port: 8080
Expand All @@ -15,20 +17,24 @@ kind: Deployment
metadata:
name: karpenter-controller
namespace: {{ .Release.Namespace }}
labels:
{{- include "karpenter.labels" . | indent 4 }}
spec:
replicas: {{ .Values.controller.replicas }}
strategy:
type: Recreate
selector:
matchLabels:
karpenter: controller
{{- include "karpenter.selectorLabels" . | indent 6 }}
template:
metadata:
labels:
karpenter: controller
{{- include "karpenter.labels" . | indent 8 }}
bwagner5 marked this conversation as resolved.
Show resolved Hide resolved
spec:
priorityClassName: system-cluster-critical
serviceAccountName: {{ .Values.serviceAccount.name }}
serviceAccountName: {{ template "karpenter.serviceAccountName" . }}
containers:
- name: manager
image: {{ .Values.controller.image }}
Expand Down
10 changes: 9 additions & 1 deletion charts/karpenter/templates/controller/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,20 +18,24 @@ 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
kind: Role
metadata:
name: karpenter-controller
namespace: {{ .Release.Namespace }}
labels:
{{- include "karpenter.labels" . | indent 4 }}
rules:
- apiGroups: [""]
resources: ["configmaps"]
Expand All @@ -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"]
Expand Down
4 changes: 3 additions & 1 deletion charts/karpenter/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.serviceAccount.name }}
name: {{ include "karpenter.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "karpenter.labels" . | indent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
11 changes: 10 additions & 1 deletion charts/karpenter/templates/webhook/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@ 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:
type: Recreate
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 }}
Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions charts/karpenter/templates/webhook/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ 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
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
kind: Role
metadata:
name: karpenter-webhook
namespace: {{ .Release.Namespace }}
labels:
{{- include "karpenter.labels" . | indent 4 }}
rules:
- apiGroups: [""]
resources: ["configmaps", "namespaces"]
Expand All @@ -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"]
Expand Down
6 changes: 6 additions & 0 deletions charts/karpenter/templates/webhook/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions charts/karpenter/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# -- Additional labels to add into metadata
additionalLabels: {}
# app: karpenter

serviceAccount:
# -- Create a service account for the application controller
create: true
Expand Down