Skip to content

Commit

Permalink
Merge pull request #90 from ktong/default_parameters
Browse files Browse the repository at this point in the history
Use default parameters in make_pod to simple tests
  • Loading branch information
yuvipanda committed Oct 31, 2017
2 parents 5ed86f1 + 7037c5e commit 55f9702
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 169 deletions.
38 changes: 19 additions & 19 deletions kubespawner/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@

def make_pod(
name,
cmd,
port,
image_spec,
image_pull_policy,
image_pull_secret,
port,
cmd,
node_selector,
run_as_uid,
fs_gid,
run_privileged,
env,
working_dir,
volumes,
volume_mounts,
labels,
cpu_limit,
cpu_guarantee,
mem_limit,
mem_guarantee,
lifecycle_hooks,
init_containers,
service_account,
image_pull_secret=None,
node_selector=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
env={},
working_dir=None,
volumes=[],
volume_mounts=[],
labels={},
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
lifecycle_hooks=None,
init_containers=None,
service_account=None
):
"""
Make a k8s pod specification for running a user notebook.
Expand Down
4 changes: 2 additions & 2 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,11 @@ def get_pod_manifest(self):

return make_pod(
name=self.pod_name,
cmd=real_cmd,
port=self.port,
image_spec=self.singleuser_image_spec,
image_pull_policy=self.singleuser_image_pull_policy,
image_pull_secret=self.singleuser_image_pull_secrets,
port=self.port,
cmd=real_cmd,
node_selector=self.singleuser_node_selector,
run_as_uid=singleuser_uid,
fs_gid=singleuser_fs_gid,
Expand Down
157 changes: 9 additions & 148 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,9 @@ def test_make_simplest_pod():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
node_selector=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
labels={},
lifecycle_hooks=None,
init_containers=None,
service_account=None
image_pull_policy='IfNotPresent'
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -72,26 +55,10 @@ def test_make_labeled_pod():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
node_selector=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
labels={"test": "true"},
lifecycle_hooks=None,
init_containers=None,
service_account=None
labels={"test": "true"}
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -130,26 +97,10 @@ def test_make_pod_with_image_pull_secrets():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
node_selector=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
image_pull_policy='IfNotPresent',
image_pull_secret='super-sekrit',
labels={},
lifecycle_hooks=None,
init_containers=None,
service_account=None
image_pull_secret='super-sekrit'
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -192,26 +143,11 @@ def test_set_pod_uid_fs_gid():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
node_selector=None,
run_as_uid=1000,
fs_gid=1000,
run_privileged=False,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
labels={},
lifecycle_hooks=None,
init_containers=None,
service_account=None
image_pull_policy='IfNotPresent'
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -253,26 +189,10 @@ def test_run_privileged_container():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
node_selector=None,
run_as_uid=None,
fs_gid=None,
run_privileged=True,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
labels={},
lifecycle_hooks=None,
init_containers=None,
service_account=None
image_pull_policy='IfNotPresent'
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -314,26 +234,15 @@ def test_make_pod_resources_all():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cpu_limit=2,
cpu_guarantee=1,
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
mem_limit='1Gi',
mem_guarantee='512Mi',
image_pull_policy='IfNotPresent',
image_pull_secret="myregistrykey",
node_selector={"disk": "ssd"},
run_as_uid=None,
fs_gid=None,
run_privileged=False,
labels={},
lifecycle_hooks=None,
init_containers=None,
service_account=None
node_selector={"disk": "ssd"}
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -384,25 +293,9 @@ def test_make_pod_with_env():
env={
'TEST_KEY': 'TEST_VALUE'
},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
node_selector=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
labels={},
lifecycle_hooks=None,
init_containers=None,
service_account=None
image_pull_policy='IfNotPresent'
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -443,32 +336,16 @@ def test_make_pod_with_lifecycle():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
labels={},
node_selector={},
lifecycle_hooks={
'preStop': {
'exec': {
'command': ['/bin/sh', 'test']
}
}
},
init_containers=None,
service_account=None
}
)) == {
"metadata": {
"name": "test",
Expand Down Expand Up @@ -517,24 +394,9 @@ def test_make_pod_with_init_containers():
assert api_client.sanitize_for_serialization(make_pod(
name='test',
image_spec='jupyter/singleuser:latest',
env={},
volumes=[],
volume_mounts=[],
cmd=['jupyterhub-singleuser'],
working_dir=None,
port=8888,
cpu_limit=None,
cpu_guarantee=None,
mem_limit=None,
mem_guarantee=None,
image_pull_policy='IfNotPresent',
image_pull_secret=None,
run_as_uid=None,
fs_gid=None,
run_privileged=False,
labels={},
lifecycle_hooks=None,
node_selector={},
init_containers=[
{
'name': 'init-myservice',
Expand All @@ -546,8 +408,7 @@ def test_make_pod_with_init_containers():
'image': 'busybox',
'command': ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']
}
],
service_account=None
]
)) == {
"metadata": {
"name": "test",
Expand Down

0 comments on commit 55f9702

Please sign in to comment.