Skip to content

Commit

Permalink
toward compatible transition for safe slugs
Browse files Browse the repository at this point in the history
- safe scheme by default
- preserve old scheme if found
- persist pvc_name and attempt to handle lack of persistence from before
- add handle_legacy_names and use_legacy_labels configuration for legacy labels
  • Loading branch information
minrk committed Jun 12, 2024
1 parent bdf0f37 commit a1b524d
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 50 deletions.
10 changes: 5 additions & 5 deletions kubespawner/slugs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tools for generating
"""Tools for generating slugs like k8s object names and labels
Requirements:
Expand All @@ -10,9 +10,9 @@
import re
import string

_alphanum = set(string.ascii_letters + string.digits)
_alphanum_lower = set(string.ascii_lowercase + string.digits)
_lower_plus_hyphen = _alphanum_lower | {'-'}
_alphanum = tuple(string.ascii_letters + string.digits)
_alphanum_lower = tuple(string.ascii_lowercase + string.digits)
_lower_plus_hyphen = _alphanum_lower + ('-',)

# patterns _do not_ need to cover length or start/end conditions,
# which are handled separately
Expand Down Expand Up @@ -85,7 +85,7 @@ def strip_and_hash(name):
"""Generate an always-safe, unique string for any input"""
# make sure we start with a prefix
# quick, short hash to avoid name collsions
name_hash = hashlib.sha256(name).hexdigest()[:8]
name_hash = hashlib.sha256(name.encode("utf8")).hexdigest()[:8]
safe_chars = [c for c in name.lower() if c in _lower_plus_hyphen]
safe_name = ''.join(safe_chars[:24])
if not safe_name:
Expand Down
Loading

0 comments on commit a1b524d

Please sign in to comment.