Skip to content

Commit

Permalink
Merge pull request #122 from yuvipanda/annotation-not-label
Browse files Browse the repository at this point in the history
Put usernames as annotations, not labels
  • Loading branch information
minrk committed Jan 22, 2018
2 parents d8d4efc + dbe675f commit 4458537
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
11 changes: 7 additions & 4 deletions kubespawner/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def make_pvc(
storage_class,
access_modes,
storage,
labels
labels,
annotations={}
):
"""
Make a k8s pvc specification for running a user notebook.
Expand All @@ -275,16 +276,18 @@ def make_pvc(
pvc.api_version = "v1"
pvc.metadata = V1ObjectMeta()
pvc.metadata.name = name
pvc.metadata.annotations = {}
if storage_class:
pvc.metadata.annotations.update({"volume.beta.kubernetes.io/storage-class": storage_class})
pvc.metadata.annotations = annotations
pvc.metadata.labels = {}
pvc.metadata.labels.update(labels)
pvc.spec = V1PersistentVolumeClaimSpec()
pvc.spec.access_modes = access_modes
pvc.spec.resources = V1ResourceRequirements()
pvc.spec.resources.requests = {"storage": storage}

if storage_class:
pvc.metadata.annotations.update({"volume.beta.kubernetes.io/storage-class": storage_class})
pvc.spec.storage_class_name = storage_class

return pvc

def make_ingress(
Expand Down
22 changes: 16 additions & 6 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,8 @@ def _build_common_labels(self, extra_labels):
labels = {
'heritage': 'jupyterhub',
'app': 'jupyterhub',
'hub.jupyter.org/username': escapism.escape(self.user.name)
}

if self.name:
# FIXME: Make sure this is dns safe?
labels['hub.jupyter.org/servername'] = self.name
labels.update(extra_labels)
return labels

Expand All @@ -801,6 +797,17 @@ def _build_pod_labels(self, extra_labels):
labels.update(self.pod_reflector.labels)
return self._build_common_labels(labels)

def _build_common_annotations(self, extra_annotations):
# Annotations don't need to be escaped
annotations = {
'hub.jupyter.org/username': self.user.name
}
if self.name:
annotations['hub.jupyter.org/servername'] = self.name

annotations.update(extra_annotations)
return annotations

@gen.coroutine
def get_pod_manifest(self):
"""
Expand All @@ -822,7 +829,7 @@ def get_pod_manifest(self):
real_cmd = None

labels = self._build_pod_labels(self._expand_all(self.singleuser_extra_labels))
annotations = self._expand_all(self.singleuser_extra_annotations)
annotations = self._build_common_annotations(self._expand_all(self.singleuser_extra_annotations))

return make_pod(
name=self.pod_name,
Expand Down Expand Up @@ -861,12 +868,15 @@ def get_pvc_manifest(self):
"""
labels = self._build_common_labels(self._expand_all(self.user_storage_extra_labels))

annotations = self._build_common_annotations({})

return make_pvc(
name=self.pvc_name,
storage_class=self.user_storage_class,
access_modes=self.user_storage_access_modes,
storage=self.user_storage_capacity,
labels=labels
labels=labels,
annotations=annotations
)

def is_pod_running(self, pod):
Expand Down
1 change: 1 addition & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ def test_make_resources_all():
}
},
'spec': {
'storageClassName': 'gce-standard-storage',
'accessModes': ['ReadWriteOnce'],
'resources': {
'requests': {
Expand Down

0 comments on commit 4458537

Please sign in to comment.