Skip to content

Commit 54ddae3

Browse files
committed
Keep fsGroup for non-Pi servers to preserve writable homes
1 parent 0c58caf commit 54ddae3

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

config/jupyterhub/08-pi-home-and-spawn-fixes.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -855,28 +855,33 @@ async def _profile_list_without_nebula_pi_cli(spawner):
855855
existing_pod_security_context.setdefault("fsGroupChangePolicy", "OnRootMismatch")
856856
c.KubeSpawner.pod_security_context = existing_pod_security_context
857857

858-
# kubespawner in this stack still emits pod fsGroup without fsGroupChangePolicy.
859-
# For RWX homes this can stall startup for many minutes. Force-disable fs_gid before spawn
860-
# and rely on explicit init-container chmod for writable paths.
861-
c.KubeSpawner.fs_gid = None
858+
# Keep fsGroup enabled for default (non-pi) servers so user home PVCs are writable
859+
# as uid 1000, while still disabling fsGroup for Pi servers (which run as root here).
860+
DEFAULT_FS_GID = int(z2jh.get_config("custom.default-fs-gid", 100) or 100)
861+
c.KubeSpawner.fs_gid = DEFAULT_FS_GID
862862

863863
_previous_pre_spawn_hook = getattr(c.Spawner, "pre_spawn_hook", None)
864864

865865

866-
async def _pre_spawn_disable_fs_gid(spawner):
867-
spawner.fs_gid = None
866+
async def _pre_spawn_adjust_fs_gid(spawner):
867+
server_name = (getattr(spawner, "name", "") or "").strip()
868+
if server_name == "pi":
869+
spawner.fs_gid = None
870+
else:
871+
spawner.fs_gid = DEFAULT_FS_GID
872+
868873
if callable(_previous_pre_spawn_hook):
869874
result = _previous_pre_spawn_hook(spawner)
870875
if inspect.isawaitable(result):
871876
await result
872877

873878

874-
c.Spawner.pre_spawn_hook = _pre_spawn_disable_fs_gid
879+
c.Spawner.pre_spawn_hook = _pre_spawn_adjust_fs_gid
875880

876881
_previous_modify_pod_hook = getattr(c.KubeSpawner, "modify_pod_hook", None)
877882

878883

879-
async def _modify_pod_strip_fs_group(spawner, pod):
884+
async def _modify_pod_adjust_fs_group(spawner, pod):
880885
if callable(_previous_modify_pod_hook):
881886
maybe_pod = _previous_modify_pod_hook(spawner, pod)
882887
if inspect.isawaitable(maybe_pod):
@@ -886,14 +891,21 @@ async def _modify_pod_strip_fs_group(spawner, pod):
886891

887892
try:
888893
sec = pod.spec.security_context
894+
server_name = (getattr(spawner, "name", "") or "").strip()
889895
if sec is not None:
890-
sec.fs_group = None
891-
sec.fs_group_change_policy = None
896+
if server_name == "pi":
897+
sec.fs_group = None
898+
sec.fs_group_change_policy = None
899+
else:
900+
if sec.fs_group is None:
901+
sec.fs_group = DEFAULT_FS_GID
902+
if getattr(sec, "fs_group_change_policy", None) is None:
903+
sec.fs_group_change_policy = "OnRootMismatch"
892904
pod.spec.security_context = sec
893905
except Exception:
894906
pass
895907

896908
return pod
897909

898910

899-
c.KubeSpawner.modify_pod_hook = _modify_pod_strip_fs_group
911+
c.KubeSpawner.modify_pod_hook = _modify_pod_adjust_fs_group

0 commit comments

Comments
 (0)