Skip to content

Commit

Permalink
move delimiter to pvc/pod name templates
Browse files Browse the repository at this point in the history
and note version change
  • Loading branch information
minrk committed Jul 3, 2020
1 parent b7f55ea commit 3dfe870
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,25 @@ def _namespace_default(self):
)

pod_name_template = Unicode(
'jupyter-{username}{servername}',
'jupyter-{username}--{servername}',
config=True,
help="""
Template to use to form the name of user's pods.
`{username}` is expanded to the escaped, dns-label safe username.
`{username}` is expanded to the escaped, dns-label-safe username.
`{servername}` is expanded to the escaped, dns-label-safe server name, if any.
Trailing `-` characters are stripped for safe handling of empty server names (user default servers).
This must be unique within the namespace the pods are being spawned
in, so if you are running multiple jupyterhubs spawning in the
same namespace, consider setting this to be something more unique.
.. versionchanged:: 0.12
`--` delimiter added to the template,
where it was implicitly added to the `servername` field before.
Additionally, `username--servername` delimiter was `-` instead of `--`,
allowing collisions in certain circumstances.
"""
)

Expand All @@ -332,16 +341,25 @@ def _namespace_default(self):
)

pvc_name_template = Unicode(
'claim-{username}{servername}',
'claim-{username}--{servername}',
config=True,
help="""
Template to use to form the name of user's pvc.
`{username}` is expanded to the escaped, dns-label safe username.
`{servername}` is expanded to the escaped, dns-label-safe server name, if any.
Trailing `-` characters are stripped for safe handling of empty server names (user default servers).
This must be unique within the namespace the pvc are being spawned
in, so if you are running multiple jupyterhubs spawning in the
same namespace, consider setting this to be something more unique.
.. versionchanged:: 0.12
`--` delimiter added to the template,
where it was implicitly added to the `servername` field before.
Additionally, `username--servername` delimiter was `-` instead of `--`,
allowing collisions in certain circumstances.
"""
)

Expand Down Expand Up @@ -1313,28 +1331,22 @@ def _expand_user_properties(self, template):
# Note: '-' is not in safe_chars, as it is being used as escape character
safe_chars = set(string.ascii_lowercase + string.digits)

# Set servername based on whether named-server initialised
if self.name:
# use two -- to ensure no collision possibilities
# are created by an ambiguous boundary between username and
# servername.
# -- cannot occur in a string where - is the escape char.
servername = '--{}'.format(self.name)
safe_servername = '--{}'.format(escapism.escape(self.name, safe=safe_chars, escape_char='-').lower())
else:
servername = ''
safe_servername = ''
raw_servername = self.name or ''
safe_servername = escapism.escape(raw_servername, safe=safe_chars, escape_char='-').lower()

legacy_escaped_username = ''.join([s if s in safe_chars else '-' for s in self.user.name.lower()])
safe_username = escapism.escape(self.user.name, safe=safe_chars, escape_char='-').lower()
return template.format(
rendered = template.format(
userid=self.user.id,
username=safe_username,
unescaped_username=self.user.name,
legacy_escape_username=legacy_escaped_username,
servername=safe_servername,
unescaped_servername=servername,
unescaped_servername=raw_servername,
)
# strip trailing - delimiter in case of empty servername.
# k8s object names cannot have trailing -
return rendered.rstrip("-")

def _expand_all(self, src):
if isinstance(src, list):
Expand Down

0 comments on commit 3dfe870

Please sign in to comment.