Skip to content

Commit

Permalink
Soft transition to modern app.kubernetes.io labels
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Apr 24, 2024
1 parent becea53 commit 8dda8b9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 85 deletions.
21 changes: 17 additions & 4 deletions kubespawner/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,21 @@ def _namespace_default(self):
'singleuser-server',
config=True,
help="""
The component label used to tag the user pods. This can be used to override
the spawner behavior when dealing with multiple hub instances in the same
namespace. Usually helpful for CI workflows.
The value of the labels app.kubernetes.io/component and component, used
to identify user pods kubespawner is to manage.
This can be used to override the spawner behavior when dealing with
multiple hub instances in the same namespace. Usually helpful for CI
workflows.
""",
)

common_labels = Dict(
{
'app.kubernetes.io/name': 'jupyterhub',
'app.kubernetes.io/managed-by': 'kubespawner',
# app and heritage are older variants of the modern
# app.kubernetes.io labels
'app': 'jupyterhub',
'heritage': 'jupyterhub',
},
Expand Down Expand Up @@ -320,6 +327,7 @@ def __init__(self, *args, **kwargs):
self.networking_api = shared_client('NetworkingV1Api')

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

common_labels = self._expand_all(self.common_labels, routespec, data)
common_labels.update({'component': self.component_label})
common_labels.update(
{
'app.kubernetes.io/component': self.component_label,
'component': self.component_label,
}
)

ingress_extra_labels = self._expand_all(
self.ingress_extra_labels, routespec, data
Expand Down
34 changes: 30 additions & 4 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,12 @@ def _namespace_default(self):
'singleuser-server',
config=True,
help="""
The component label used to tag the user pods. This can be used to override
the spawner behavior when dealing with multiple hub instances in the same
namespace. Usually helpful for CI workflows.
The value of the labels app.kubernetes.io/component and component, used
to identify user pods kubespawner is to manage.
This can be used to override the spawner behavior when dealing with
multiple hub instances in the same namespace. Usually helpful for CI
workflows.
""",
)

Expand Down Expand Up @@ -655,6 +658,10 @@ def _deprecated_changed(self, change):

common_labels = Dict(
{
'app.kubernetes.io/name': 'jupyterhub',
'app.kubernetes.io/managed-by': 'kubespawner',
# app and heritage are older variants of the modern
# app.kubernetes.io labels
'app': 'jupyterhub',
'heritage': 'jupyterhub',
},
Expand Down Expand Up @@ -1878,6 +1885,7 @@ def _build_pod_labels(self, extra_labels):
labels = self._build_common_labels(extra_labels)
labels.update(
{
'app.kubernetes.io/component': self.component_label,
'component': self.component_label,
'hub.jupyter.org/servername': escapism.escape(
self.name, safe=self.safe_chars, escape_char='-'
Expand Down Expand Up @@ -2102,7 +2110,17 @@ def get_pvc_manifest(self):
Make a pvc manifest that will spawn current user's pvc.
"""
labels = self._build_common_labels(self._expand_all(self.storage_extra_labels))
labels.update({'component': 'singleuser-storage'})
labels.update(
{
# The component label has been set to singleuser-storage, but should
# probably have been set to singleuser-server (self.component_label)
# as that ties it to the user pods kubespawner creates. Due to that,
# the newly introduced label app.kubernetes.io/component gets
# singleuser-server (self.component_label) as a value instead.
'app.kubernetes.io/component': self.component_label,
'component': 'singleuser-storage',
}
)

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

0 comments on commit 8dda8b9

Please sign in to comment.