Skip to content

Commit 5ad350e

Browse files
authored
Merge pull request #3596 from samyuh/ft-fix
Add modern labels to pods controlled by deployments etc.
2 parents b3fb34b + 6c7787c commit 5ad350e

File tree

8 files changed

+79
-18
lines changed

8 files changed

+79
-18
lines changed

jupyterhub/templates/_helpers.tpl

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,52 +124,113 @@
124124
app.kubernetes.io/managed-by ("heritage")
125125
*/}}
126126
{{- define "jupyterhub.commonLabels" -}}
127+
{{- if .legacyLabels -}}
127128
app: {{ .appLabel | default (include "jupyterhub.appLabel" .) | quote }}
128129
release: {{ .Release.Name | quote }}
129130
{{- if not .matchLabels }}
130131
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
131132
heritage: {{ .Release.Service }}
133+
{{- end }}
134+
{{- end }}
135+
{{- if and .legacyLabels .modernLabels -}}
136+
{{ printf "\n" }}
137+
{{- end }}
138+
{{- if .modernLabels -}}
132139
app.kubernetes.io/name: {{ .appLabel | default (include "jupyterhub.appLabel" .) | quote }}
133140
app.kubernetes.io/instance: {{ .Release.Name | quote }}
141+
{{- if not .matchLabels }}
134142
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
135143
app.kubernetes.io/managed-by: {{ .Release.Service }}
136144
{{- end }}
137145
{{- end }}
146+
{{- end }}
138147
139148
140149
{{- /*
141150
jupyterhub.labels:
142-
Provides old labels:
151+
Provides labels conditionally on .legacyLabels, .modernLabels, and .matchLabels,
152+
that are supposed to in the scoped passed this helper function.
153+
154+
The legacy labels are:
143155
component
144156
app
145157
release
146158
chart (omitted for matchLabels)
147159
heritage (omitted for matchLabels)
148-
Provides modern labels (omitted for matchLabels):
149-
app.kubernetes.io/component ("component")
150-
app.kubernetes.io/name ("app")
151-
app.kubernetes.io/instance release ("release")
152-
helm.sh/chart ("chart")
153-
app.kubernetes.io/managed-by ("heritage")
160+
161+
The equivalent modern labels are:
162+
app.kubernetes.io/component
163+
app.kubernetes.io/name
164+
app.kubernetes.io/instance release
165+
helm.sh/chart (omitted for matchLabels)
166+
app.kubernetes.io/managed-by (omitted for matchLabels)
154167
*/}}
155168
{{- define "jupyterhub.labels" -}}
169+
{{- /*
170+
.legacyLabels defaults to true
171+
.modernLabels defaults to false
172+
*/ -}}
173+
{{- $_ := . -}}
174+
{{- if typeIs "<nil>" .legacyLabels -}}
175+
{{- $_ = merge (dict "legacyLabels" true) $_ -}}
176+
{{- end -}}
177+
{{- if typeIs "<nil>" .modernLabels -}}
178+
{{- $_ = merge (dict "modernLabels" true) $_ -}}
179+
{{- end -}}
180+
181+
{{- if $_.legacyLabels -}}
156182
component: {{ include "jupyterhub.componentLabel" . }}
157-
{{- if not .matchLabels }}
183+
{{- end }}
184+
185+
{{- if and $_.legacyLabels $_.modernLabels -}}
186+
{{ printf "\n" }}
187+
{{- end }}
188+
189+
{{- if $_.modernLabels -}}
158190
app.kubernetes.io/component: {{ include "jupyterhub.componentLabel" . }}
159191
{{- end }}
160-
{{ include "jupyterhub.commonLabels" . }}
192+
{{ include "jupyterhub.commonLabels" $_ }}
161193
{{- end }}
162194
163195
164196
{{- /*
165197
jupyterhub.matchLabels:
166-
Provides old labels:
198+
Provides legacy labels:
167199
component
168200
app
169201
release
170202
*/}}
171203
{{- define "jupyterhub.matchLabels" -}}
172-
{{- $_ := merge (dict "matchLabels" true) . -}}
204+
{{- $_ := merge (dict "matchLabels" true "legacyLabels" true "modernLabels" false) . -}}
205+
{{ include "jupyterhub.labels" $_ }}
206+
{{- end }}
207+
208+
209+
{{- /*
210+
jupyterhub.matchLabelsModern:
211+
Provides modern labels:
212+
app.kubernetes.io/component
213+
app.kubernetes.io/name
214+
app.kubernetes.io/instance
215+
*/}}
216+
{{- define "jupyterhub.matchLabelsModern" -}}
217+
{{- $_ := merge (dict "matchLabels" true "legacyLabels" false "modernLabels" true) . -}}
218+
{{ include "jupyterhub.labels" $_ }}
219+
{{- end }}
220+
221+
222+
{{- /*
223+
jupyterhub.matchLabelsLegacyAndModern:
224+
Provides legacy and modern labels:
225+
component
226+
app
227+
release
228+
app.kubernetes.io/component
229+
app.kubernetes.io/name
230+
app.kubernetes.io/instance
231+
*/}}
232+
{{- define "jupyterhub.matchLabelsLegacyAndModern" -}}
233+
{{- $_ := merge (dict "matchLabels" true "legacyLabels" true "modernLabels" true) . -}}
173234
{{ include "jupyterhub.labels" $_ }}
174235
{{- end }}
175236

jupyterhub/templates/hub/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
metadata:
1919
labels:
2020
{{- /* Changes here will cause the Deployment to restart the pods. */}}
21-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
21+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
2222
hub.jupyter.org/network-access-proxy-api: "true"
2323
hub.jupyter.org/network-access-proxy-http: "true"
2424
hub.jupyter.org/network-access-singleuser: "true"

jupyterhub/templates/image-puller/_helpers-daemonset.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spec:
4040
template:
4141
metadata:
4242
labels:
43-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
43+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
4444
{{- with .Values.prePuller.annotations }}
4545
annotations:
4646
{{- . | toYaml | nindent 8 }}

jupyterhub/templates/image-puller/job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
metadata:
2828
labels:
2929
{{- /* Changes here will cause the Job to restart the pods. */}}
30-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
30+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
3131
{{- with .Values.prePuller.labels }}
3232
{{- . | toYaml | nindent 8 }}
3333
{{- end }}

jupyterhub/templates/proxy/autohttps/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
template:
1919
metadata:
2020
labels:
21-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
21+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
2222
hub.jupyter.org/network-access-proxy-http: "true"
2323
{{- with .Values.proxy.traefik.labels }}
2424
{{- . | toYaml | nindent 8 }}

jupyterhub/templates/proxy/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
metadata:
2121
labels:
2222
{{- /* Changes here will cause the Deployment to restart the pods. */}}
23-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
23+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
2424
hub.jupyter.org/network-access-hub: "true"
2525
hub.jupyter.org/network-access-singleuser: "true"
2626
{{- with .Values.proxy.labels }}

jupyterhub/templates/scheduling/user-placeholder/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
{{- end }}
3333
labels:
3434
{{- /* Changes here will cause the Deployment to restart the pods. */}}
35-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
35+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
3636
{{- with .Values.scheduling.userPlaceholder.labels }}
3737
{{- . | toYaml | nindent 8 }}
3838
{{- end }}

jupyterhub/templates/scheduling/user-scheduler/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spec:
1616
template:
1717
metadata:
1818
labels:
19-
{{- include "jupyterhub.matchLabels" . | nindent 8 }}
19+
{{- include "jupyterhub.matchLabelsLegacyAndModern" . | nindent 8 }}
2020
{{- with .Values.scheduling.userScheduler.labels }}
2121
{{- . | toYaml | nindent 8 }}
2222
{{- end }}

0 commit comments

Comments
 (0)