Skip to content

Commit 83f6677

Browse files
committed
Use per-component matchLabels selector in pod specs (fix #355)
Signed-off-by: Dr. Jan-Philip Gehrcke <[email protected]>
1 parent bf444c4 commit 83f6677

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

deployments/helm/nvidia-dra-driver-gpu/templates/_helpers.tpl

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,47 @@ Create chart name and version as used by the chart label.
4343
{{- end }}
4444

4545
{{/*
46-
Common labels
46+
Standard labels: documented at
47+
https://helm.sh/docs/chart_best_practices/labels/
48+
Apply this to all high-level objects (Deployment, DaemonSet, ...).
49+
Pod template labels are included here to deliver name+instance.
4750
*/}}
4851
{{- define "nvidia-dra-driver-gpu.labels" -}}
4952
helm.sh/chart: {{ include "nvidia-dra-driver-gpu.chart" . }}
50-
{{ include "nvidia-dra-driver-gpu.templateLabels" . }}
51-
{{- if .Chart.AppVersion }}
5253
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
53-
{{- end }}
5454
app.kubernetes.io/managed-by: {{ .Release.Service }}
55+
{{ include "nvidia-dra-driver-gpu.templateLabels" . }}
5556
{{- end }}
5657

5758
{{/*
58-
Template labels
59+
Apply this to all pod templates (a smaller set of labels compared to
60+
the set of standard labels above, to not clutter individual pods too
61+
much). Note that these labels cannot be used to distinguish
62+
components within this Helm chart.
5963
*/}}
6064
{{- define "nvidia-dra-driver-gpu.templateLabels" -}}
6165
app.kubernetes.io/name: {{ include "nvidia-dra-driver-gpu.name" . }}
6266
app.kubernetes.io/instance: {{ .Release.Name }}
63-
{{- if .Values.selectorLabelsOverride }}
64-
{{ toYaml .Values.selectorLabelsOverride }}
65-
{{- end }}
6667
{{- end }}
6768

6869
{{/*
69-
Selector labels
70+
Selector label: precisely filter for just the pods of the corresponding
71+
Deployment, DaemonSet, .... That is, this label key/value pair must be
72+
different per-component (a component name is a required argument). This
73+
could be many labels, but we want to use just one (with a sufficiently
74+
unique key).
75+
76+
TOOD: remove the override feature, or make the override work per-component.
7077
*/}}
7178
{{- define "nvidia-dra-driver-gpu.selectorLabels" -}}
72-
{{- if .Values.selectorLabelsOverride -}}
73-
{{ toYaml .Values.selectorLabelsOverride }}
79+
{{- if and (hasKey . "componentName") (hasKey . "context") -}}
80+
{{- if .context.Values.selectorLabelsOverride -}}
81+
{{ toYaml .context.Values.selectorLabelsOverride }}
7482
{{- else -}}
75-
{{ include "nvidia-dra-driver-gpu.templateLabels" . }}
83+
{{ .context.Chart.Name }}-component: {{ .componentName }}
84+
{{- end }}
85+
{{- else -}}
86+
fail "selectorLabels: both arguments are required: context, componentName"
7687
{{- end }}
7788
{{- end }}
7889

deployments/helm/nvidia-dra-driver-gpu/templates/controller.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
replicas: 1
2626
selector:
2727
matchLabels:
28-
{{- include "nvidia-dra-driver-gpu.selectorLabels" . | nindent 6 }}
28+
{{- include "nvidia-dra-driver-gpu.selectorLabels" (dict "context" . "componentName" "controller") | nindent 6 }}
2929
template:
3030
metadata:
3131
{{- with .Values.controller.podAnnotations }}
@@ -34,6 +34,7 @@ spec:
3434
{{- end }}
3535
labels:
3636
{{- include "nvidia-dra-driver-gpu.templateLabels" . | nindent 8 }}
37+
{{- include "nvidia-dra-driver-gpu.selectorLabels" (dict "context" . "componentName" "controller") | nindent 8 }}
3738
spec:
3839
{{- if .Values.controller.priorityClassName }}
3940
priorityClassName: {{ .Values.controller.priorityClassName }}

deployments/helm/nvidia-dra-driver-gpu/templates/kubeletplugin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ metadata:
2424
spec:
2525
selector:
2626
matchLabels:
27-
{{- include "nvidia-dra-driver-gpu.selectorLabels" . | nindent 6 }}
27+
{{- include "nvidia-dra-driver-gpu.selectorLabels" (dict "context" . "componentName" "kubelet-plugin") | nindent 6 }}
2828
{{- with .Values.kubeletPlugin.updateStrategy }}
2929
updateStrategy:
3030
{{- toYaml . | nindent 4 }}
@@ -37,6 +37,7 @@ spec:
3737
{{- end }}
3838
labels:
3939
{{- include "nvidia-dra-driver-gpu.templateLabels" . | nindent 8 }}
40+
{{- include "nvidia-dra-driver-gpu.selectorLabels" (dict "context" . "componentName" "kubelet-plugin") | nindent 8 }}
4041
spec:
4142
{{- if .Values.kubeletPlugin.priorityClassName }}
4243
priorityClassName: {{ .Values.kubeletPlugin.priorityClassName }}

0 commit comments

Comments
 (0)