Skip to content

Commit

Permalink
Merge pull request #161 from consideRatio/labels-pr
Browse files Browse the repository at this point in the history
Add common labels for Pods & PVCs
  • Loading branch information
minrk committed May 29, 2018
2 parents 94dc895 + 0f87c23 commit cff7f01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
3 changes: 0 additions & 3 deletions kubespawner/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
class IngressReflector(NamespacedResourceReflector):
kind = 'ingresses'
labels = {
'heritage': 'jupyterhub',
'component': 'singleuser-server',
'hub.jupyter.org/proxy-route': 'true'
}
Expand All @@ -35,7 +34,6 @@ def ingresses(self):
class ServiceReflector(NamespacedResourceReflector):
kind = 'services'
labels = {
'heritage': 'jupyterhub',
'component': 'singleuser-server',
'hub.jupyter.org/proxy-route': 'true'
}
Expand All @@ -49,7 +47,6 @@ def services(self):
class EndpointsReflector(NamespacedResourceReflector):
kind = 'endpoints'
labels = {
'heritage': 'jupyterhub',
'component': 'singleuser-server',
'hub.jupyter.org/proxy-route': 'true'
}
Expand Down
43 changes: 29 additions & 14 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

class PodReflector(NamespacedResourceReflector):
kind = 'pods'

# FUTURE: These labels are the selection labels for the PodReflector. We
# might want to support multiple deployments in the same namespace, so we
# would need to select based on additional labels such as `app` and
# `release`.
labels = {
'heritage': 'jupyterhub',
'component': 'singleuser-server',
}

Expand Down Expand Up @@ -287,6 +289,21 @@ def _hub_connect_port_default(self):
"""
return self.hub.server.port

common_labels = Dict(
{
'app': 'jupyterhub',
'heritage': 'jupyterhub',
},
config=True,
help="""
Kubernetes labels that both spawned singleuser server pods and created
user PVCs will get.
Note that these are only set when the Pods and PVCs are created, not
later when this setting is updated.
"""
)

singleuser_extra_labels = Dict(
{},
config=True,
Expand Down Expand Up @@ -592,7 +609,7 @@ def _hub_connect_port_default(self):
The keys and values specified here would be set as labels on the PVCs
created by kubespawner for the user. Note that these are only set
when the PVC is created, not later when they are updated.
when the PVC is created, not later when this setting is updated.
See https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ for more
info on what labels are and why you might want to use them!
Expand Down Expand Up @@ -939,22 +956,17 @@ def _expand_all(self, src):
def _build_common_labels(self, extra_labels):
# Default set of labels, picked up from
# https://github.com/kubernetes/helm/blob/master/docs/chart_best_practices/labels.md
labels = {
'heritage': 'jupyterhub',
'app': 'jupyterhub',
}

labels = {}
labels.update(extra_labels)
labels.update(self.common_labels)
return labels

def _build_pod_labels(self, extra_labels):
labels = {
labels = self._build_common_labels(extra_labels)
labels.update({
'component': 'singleuser-server'
}
labels.update(extra_labels)
# Make sure pod_reflector.labels in final label list
labels.update(self.pod_reflector.labels)
return self._build_common_labels(labels)
})
return labels

def _build_common_annotations(self, extra_annotations):
# Annotations don't need to be escaped
Expand Down Expand Up @@ -1032,6 +1044,9 @@ 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.user_storage_extra_labels))
labels.update({
'component': 'singleuser-storage'
})

annotations = self._build_common_annotations({})

Expand Down

0 comments on commit cff7f01

Please sign in to comment.