Skip to content

Commit 06114e0

Browse files
committed
Add recommended chart labels alongside old labels
This enables us to make a breaking change in z2jh 5 where user servers restarted once or more during z2jh 4 doesn't have to be restarted as part of the breaking change then. If we did it right away, network policy enforcement would fail for old servers for example. Before z2jh 4, we should also get kubespawner to specify `app.kubernetes.io/component` alongisde `component`. Also, its nice to be able to provide time for people to adjust to the new labels with a period of overlapping labels. For example, grafana dashboards working with prometheus metrics could keep working in this period and at any time transition to refering to new labels, and then when we get z2jh 5 released such dashboards could have already adjusted.
1 parent c5f66ec commit 06114e0

File tree

8 files changed

+70
-29
lines changed

8 files changed

+70
-29
lines changed

ci/common

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ await_autohttps_tls_cert_acquisition() {
5050
kubectl logs deploy/pebble --all-containers # --prefix
5151
kubectl describe pod -l app.kubernetes.io/name=pebble-coredns
5252
kubectl logs deploy/pebble-coredns --all-containers # --prefix
53-
kubectl describe pod -l component=autohttps
53+
kubectl describe pod -l app.kubernetes.io/component=autohttps
5454
kubectl logs deploy/autohttps --all-containers # --prefix
5555
exit 1
5656
fi
@@ -72,7 +72,7 @@ await_autohttps_tls_cert_save() {
7272
kubectl logs deploy/pebble --all-containers # --prefix
7373
kubectl describe pod -l app.kubernetes.io/name=pebble-coredns
7474
kubectl logs deploy/pebble-coredns --all-containers # --prefix
75-
kubectl describe pod -l component=autohttps
75+
kubectl describe pod -l app.kubernetes.io/component=autohttps
7676
kubectl logs deploy/autohttps --all-containers # --prefix
7777
exit 1
7878
fi

docs/source/administrator/services.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ proxy:
8282
- to:
8383
- podSelector:
8484
matchLabels:
85-
app: jupyterhub
86-
component: hub
85+
app.kubernetes.io/name: jupyterhub
86+
app.kubernetes.io/component: hub
8787
ports:
8888
- port: 8181
8989
```

docs/source/resources/community.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ user pods. You can search for all user pods with the following label query:
9494

9595
```bash
9696
kubectl --namespace=<YOUR-NAMESPACE> get pod \
97-
-l "component=singleuser-server"
97+
-l "app.kubernetes.io/component=singleuser-server"
9898
```
9999

100100
For more information, see the [Kubernetes labels and selectors page](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/).

jupyterhub/files/hub/jupyterhub_config.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,36 @@ def camelCaseify(s):
107107
)
108108

109109
# implement common labels
110-
# this duplicates the jupyterhub.commonLabels helper
110+
# This mimics the jupyterhub.commonLabels helper, but declares managed-by to
111+
# kubespawner instead of helm.
112+
#
113+
# The labels app and release are old labels enabled to be deleted in z2jh 5, but
114+
# for now retained to avoid a breaking change in z2jh 4 that would force user
115+
# server restarts. Restarts would be required because NetworkPolicy resources
116+
# must select old/new pods with labels that then needs to be seen on both
117+
# old/new pods, and we want these resources to keep functioning for old/new user
118+
# server pods during an upgrade.
119+
#
111120
common_labels = c.KubeSpawner.common_labels = {}
112-
common_labels["app"] = get_config(
121+
common_labels["app.kubernetes.io/name"] = common_labels["app"] = get_config(
113122
"nameOverride",
114123
default=get_config("Chart.Name", "jupyterhub"),
115124
)
116-
common_labels["heritage"] = "jupyterhub"
125+
release = get_config("Release.Name")
126+
if release:
127+
common_labels["app.kubernetes.io/instance"] = common_labels["release"] = release
117128
chart_name = get_config("Chart.Name")
118129
chart_version = get_config("Chart.Version")
119130
if chart_name and chart_version:
120-
common_labels["chart"] = "{}-{}".format(
121-
chart_name,
122-
chart_version.replace("+", "_"),
123-
)
124-
release = get_config("Release.Name")
125-
if release:
126-
common_labels["release"] = release
131+
common_labels["helm.sh/chart"] = f"{chart_name}-{chart_version.replace('+', '_')}"
132+
chart_app_version = get_config("Chart.AppVersion")
133+
if chart_app_version:
134+
common_labels["app.kubernetes.io/version"] = chart_app_version
135+
common_labels["app.kubernetes.io/managed-by"] = "kubespawner"
127136

128137
c.KubeSpawner.namespace = os.environ.get("POD_NAMESPACE", "default")
129138

130139
# Max number of consecutive failures before the Hub restarts itself
131-
# requires jupyterhub 0.9.2
132140
set_config_if_not_none(
133141
c.Spawner,
134142
"consecutive_failure_limit",

jupyterhub/templates/_helpers.tpl

+40-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
- commonLabels | uses appLabel
4949
- labels | uses commonLabels
5050
- matchLabels | uses labels
51-
- podCullerSelector | uses matchLabels
5251

5352

5453
## Example usage
@@ -112,31 +111,65 @@
112111
{{- /*
113112
jupyterhub.commonLabels:
114113
Foundation for "jupyterhub.labels".
115-
Provides labels: app, release, (chart and heritage).
114+
115+
Provides old labels:
116+
app
117+
release
118+
chart (omitted for matchLabels)
119+
heritage (omitted for matchLabels)
120+
Provides modern labels (omitted for matchLabels):
121+
app.kubernetes.io/name ("app")
122+
app.kubernetes.io/version
123+
app.kubernetes.io/instance release ("release")
124+
helm.sh/chart ("chart")
125+
app.kubernetes.io/managed-by ("heritage")
116126
*/}}
117127
{{- define "jupyterhub.commonLabels" -}}
118-
app: {{ .appLabel | default (include "jupyterhub.appLabel" .) }}
119-
release: {{ .Release.Name }}
128+
app: {{ .appLabel | default (include "jupyterhub.appLabel" .) | quote }}
129+
release: {{ .Release.Name | quote }}
120130
{{- if not .matchLabels }}
121131
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
122-
heritage: {{ .heritageLabel | default .Release.Service }}
132+
heritage: {{ .Release.Service }}
133+
app.kubernetes.io/name: {{ .appLabel | default (include "jupyterhub.appLabel" .) | quote }}
134+
app.kubernetes.io/instance: {{ .Release.Name | quote }}
135+
app.kubernetes.io/version: {{ .Chart.AppVersion }}
136+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
137+
app.kubernetes.io/managed-by: {{ .Release.Service }}
123138
{{- end }}
124139
{{- end }}
125140
126141
127142
{{- /*
128143
jupyterhub.labels:
129-
Provides labels: component, app, release, (chart and heritage).
144+
Provides old labels:
145+
component
146+
app
147+
release
148+
chart (omitted for matchLabels)
149+
heritage (omitted for matchLabels)
150+
Provides modern labels (omitted for matchLabels):
151+
app.kubernetes.io/component ("component")
152+
app.kubernetes.io/name ("app")
153+
app.kubernetes.io/version
154+
app.kubernetes.io/instance release ("release")
155+
helm.sh/chart ("chart")
156+
app.kubernetes.io/managed-by ("heritage")
130157
*/}}
131158
{{- define "jupyterhub.labels" -}}
132159
component: {{ include "jupyterhub.componentLabel" . }}
160+
{{- if not .matchLabels }}
161+
app.kubernetes.io/component: {{ include "jupyterhub.componentLabel" . }}
162+
{{- end }}
133163
{{ include "jupyterhub.commonLabels" . }}
134164
{{- end }}
135165
136166
137167
{{- /*
138168
jupyterhub.matchLabels:
139-
Used to provide pod selection labels: component, app, release.
169+
Provides old labels:
170+
component
171+
app
172+
release
140173
*/}}
141174
{{- define "jupyterhub.matchLabels" -}}
142175
{{- $_ := merge (dict "matchLabels" true) . -}}

jupyterhub/templates/proxy/autohttps/deployment.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ spec:
130130
{{- end }}
131131
args:
132132
- watch-save
133-
- --label=app={{ include "jupyterhub.appLabel" . }}
134-
- --label=release={{ .Release.Name }}
135-
- --label=chart={{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
136-
- --label=heritage=secret-sync
133+
- --label=app.kubernetes.io/name={{ include "jupyterhub.appLabel" . }}
134+
- --label=app.kubernetes.io/instance={{ .Release.Name }}
135+
- --label=helm.sh/chart={{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
136+
- --label=app.kubernetes.io/managed-by=secret-sync
137137
- {{ include "jupyterhub.proxy-public-tls.fullname" . }}
138138
- acme.json
139139
- /etc/acme/acme.json

jupyterhub/values.schema.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ properties:
625625
- to:
626626
- podSelector:
627627
matchLabels:
628-
app: my-k8s-local-service
628+
app.kubernetes.io/name: my-k8s-local-service
629629
ports:
630630
- protocol: TCP
631631
port: 5978

tools/templates/lint-and-validate-values.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ hub:
186186
- to:
187187
- podSelector:
188188
matchLabels:
189-
app: my-k8s-local-service
189+
app.kubernetes.io/name: my-k8s-local-service
190190
ports:
191191
- protocol: TCP
192192
port: 5978

0 commit comments

Comments
 (0)