Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set spec hostname to get headless service to work #626

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kubespawner/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def _get_env_var_deps(env):
changes_name="extra_pod_config",
)

pod.spec.hostname = name
return pod


Expand Down
36 changes: 36 additions & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_make_simplest_pod():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -76,6 +77,7 @@ def test_make_labeled_pod():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -118,6 +120,7 @@ def test_make_annotated_pod():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -161,6 +164,7 @@ def test_make_pod_with_image_pull_secrets_simplified_format():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -204,6 +208,7 @@ def test_make_pod_with_image_pull_secrets_k8s_native_format():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -251,6 +256,7 @@ def test_set_container_uid_and_gid():
"resources": {"limits": {}, "requests": {}},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -297,6 +303,7 @@ def test_set_container_uid_and_pod_fs_gid():
"resources": {"limits": {}, "requests": {}},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'securityContext': {
'fsGroup': 0,
Expand Down Expand Up @@ -346,6 +353,7 @@ def test_set_pod_supplemental_gids():
"resources": {"limits": {}, "requests": {}},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'securityContext': {
'supplementalGroups': [100],
Expand Down Expand Up @@ -394,6 +402,7 @@ def test_privileged_container():
'volumeMounts': [],
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -436,6 +445,7 @@ def test_allow_privilege_escalation_container():
'volumeMounts': [],
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -493,6 +503,7 @@ def test_pod_security_context_container():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'securityContext': {
'supplementalGroups': [200],
Expand Down Expand Up @@ -577,6 +588,7 @@ def test_container_security_context_container():
},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -669,6 +681,7 @@ def test_make_pod_resources_all():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -768,6 +781,7 @@ def test_make_pod_with_env():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -860,6 +874,7 @@ def test_make_pod_with_env_dependency_sorted():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -905,6 +920,7 @@ def test_make_pod_with_lifecycle():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -986,6 +1002,7 @@ def test_make_pod_with_init_containers():
],
},
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -1031,6 +1048,7 @@ def test_make_pod_with_extra_container_config():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -1088,6 +1106,7 @@ def test_make_pod_with_extra_pod_config():
],
'volumes': [],
'dnsPolicy': 'ClusterFirstWithHostNet',
'hostname': 'test',
'restartPolicy': 'Always',
'tolerations': [
{
Expand Down Expand Up @@ -1147,6 +1166,7 @@ def test_make_pod_with_extra_containers():
'command': ['/usr/local/bin/supercronic', '/etc/crontab'],
},
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -1208,6 +1228,7 @@ def test_make_pod_with_extra_resources():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -1327,6 +1348,7 @@ def test_make_pod_with_service_account():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
'serviceAccountName': 'test',
Expand Down Expand Up @@ -1367,6 +1389,7 @@ def test_make_pod_with_service_account_and_with_automount_sa_token():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
'serviceAccountName': 'test',
Expand Down Expand Up @@ -1407,6 +1430,7 @@ def test_make_pod_with_service_account_and_with_negative_automount_sa_token():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
'serviceAccountName': 'test',
Expand Down Expand Up @@ -1446,6 +1470,7 @@ def test_make_pod_with_automount_service_account_token():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -1484,6 +1509,7 @@ def test_make_pod_with_negative_automount_service_account_token():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
},
Expand Down Expand Up @@ -1526,6 +1552,7 @@ def test_make_pod_with_scheduler_name():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
'schedulerName': 'my-custom-scheduler',
Expand Down Expand Up @@ -1574,6 +1601,7 @@ def test_make_pod_with_tolerations():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
'tolerations': tolerations,
Expand Down Expand Up @@ -1627,6 +1655,7 @@ def test_make_pod_with_node_affinity_preferred():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
"volumes": [],
"affinity": {
Expand Down Expand Up @@ -1681,6 +1710,7 @@ def test_make_pod_with_node_affinity_required():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
"volumes": [],
"affinity": {
Expand Down Expand Up @@ -1743,6 +1773,7 @@ def test_make_pod_with_pod_affinity_preferred():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
"volumes": [],
"affinity": {
Expand Down Expand Up @@ -1800,6 +1831,7 @@ def test_make_pod_with_pod_affinity_required():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
"volumes": [],
"affinity": {
Expand Down Expand Up @@ -1860,6 +1892,7 @@ def test_make_pod_with_pod_anti_affinity_preferred():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
"volumes": [],
"affinity": {
Expand Down Expand Up @@ -1917,6 +1950,7 @@ def test_make_pod_with_pod_anti_affinity_required():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
"volumes": [],
"affinity": {
Expand Down Expand Up @@ -1964,6 +1998,7 @@ def test_make_pod_with_priority_class_name():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'test',
'restartPolicy': 'OnFailure',
'volumes': [],
'priorityClassName': 'my-custom-priority-class',
Expand Down Expand Up @@ -2242,6 +2277,7 @@ def test_make_pod_with_ssl():
"securityContext": {"allowPrivilegeEscalation": False},
}
],
'hostname': 'ssl',
'restartPolicy': 'OnFailure',
'volumes': [
{
Expand Down