Skip to content

Commit 8dda8b9

Browse files
committed
Soft transition to modern app.kubernetes.io labels
1 parent becea53 commit 8dda8b9

File tree

4 files changed

+87
-85
lines changed

4 files changed

+87
-85
lines changed

kubespawner/proxy.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,21 @@ def _namespace_default(self):
156156
'singleuser-server',
157157
config=True,
158158
help="""
159-
The component label used to tag the user pods. This can be used to override
160-
the spawner behavior when dealing with multiple hub instances in the same
161-
namespace. Usually helpful for CI workflows.
159+
The value of the labels app.kubernetes.io/component and component, used
160+
to identify user pods kubespawner is to manage.
161+
162+
This can be used to override the spawner behavior when dealing with
163+
multiple hub instances in the same namespace. Usually helpful for CI
164+
workflows.
162165
""",
163166
)
164167

165168
common_labels = Dict(
166169
{
170+
'app.kubernetes.io/name': 'jupyterhub',
171+
'app.kubernetes.io/managed-by': 'kubespawner',
172+
# app and heritage are older variants of the modern
173+
# app.kubernetes.io labels
167174
'app': 'jupyterhub',
168175
'heritage': 'jupyterhub',
169176
},
@@ -320,6 +327,7 @@ def __init__(self, *args, **kwargs):
320327
self.networking_api = shared_client('NetworkingV1Api')
321328

322329
labels = {
330+
'app.kubernetes.io/component': self.component_label,
323331
'component': self.component_label,
324332
'hub.jupyter.org/proxy-route': 'true',
325333
}
@@ -421,7 +429,12 @@ async def add_route(self, routespec, target, data):
421429
full_name = f'{self.namespace}/{safe_name}'
422430

423431
common_labels = self._expand_all(self.common_labels, routespec, data)
424-
common_labels.update({'component': self.component_label})
432+
common_labels.update(
433+
{
434+
'app.kubernetes.io/component': self.component_label,
435+
'component': self.component_label,
436+
}
437+
)
425438

426439
ingress_extra_labels = self._expand_all(
427440
self.ingress_extra_labels, routespec, data

kubespawner/spawner.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,12 @@ def _namespace_default(self):
596596
'singleuser-server',
597597
config=True,
598598
help="""
599-
The component label used to tag the user pods. This can be used to override
600-
the spawner behavior when dealing with multiple hub instances in the same
601-
namespace. Usually helpful for CI workflows.
599+
The value of the labels app.kubernetes.io/component and component, used
600+
to identify user pods kubespawner is to manage.
601+
602+
This can be used to override the spawner behavior when dealing with
603+
multiple hub instances in the same namespace. Usually helpful for CI
604+
workflows.
602605
""",
603606
)
604607

@@ -655,6 +658,10 @@ def _deprecated_changed(self, change):
655658

656659
common_labels = Dict(
657660
{
661+
'app.kubernetes.io/name': 'jupyterhub',
662+
'app.kubernetes.io/managed-by': 'kubespawner',
663+
# app and heritage are older variants of the modern
664+
# app.kubernetes.io labels
658665
'app': 'jupyterhub',
659666
'heritage': 'jupyterhub',
660667
},
@@ -1878,6 +1885,7 @@ def _build_pod_labels(self, extra_labels):
18781885
labels = self._build_common_labels(extra_labels)
18791886
labels.update(
18801887
{
1888+
'app.kubernetes.io/component': self.component_label,
18811889
'component': self.component_label,
18821890
'hub.jupyter.org/servername': escapism.escape(
18831891
self.name, safe=self.safe_chars, escape_char='-'
@@ -2102,7 +2110,17 @@ def get_pvc_manifest(self):
21022110
Make a pvc manifest that will spawn current user's pvc.
21032111
"""
21042112
labels = self._build_common_labels(self._expand_all(self.storage_extra_labels))
2105-
labels.update({'component': 'singleuser-storage'})
2113+
labels.update(
2114+
{
2115+
# The component label has been set to singleuser-storage, but should
2116+
# probably have been set to singleuser-server (self.component_label)
2117+
# as that ties it to the user pods kubespawner creates. Due to that,
2118+
# the newly introduced label app.kubernetes.io/component gets
2119+
# singleuser-server (self.component_label) as a value instead.
2120+
'app.kubernetes.io/component': self.component_label,
2121+
'component': 'singleuser-storage',
2122+
}
2123+
)
21062124

21072125
annotations = self._build_common_annotations(
21082126
self._expand_all(self.storage_extra_annotations)
@@ -2473,6 +2491,14 @@ async def _start_watching_pods(self, replace=False):
24732491
return await self._start_reflector(
24742492
kind="pods",
24752493
reflector_class=PodReflector,
2494+
# NOTE: We monitor pods with the old component label instead of the
2495+
# modern app.kubernetes.io/component label. A change here is
2496+
# only non-breaking if we can assume the running pods we want
2497+
# to monitor can be detected by either the old or modern
2498+
# label.
2499+
#
2500+
# Related to https://github.com/jupyterhub/kubespawner/issues/834
2501+
#
24762502
labels={"component": self.component_label},
24772503
omit_namespace=self.enable_user_namespaces,
24782504
replace=replace,

0 commit comments

Comments
 (0)