Skip to content

Commit

Permalink
fix error that put nodeSpec in wrong place in Workflow manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis committed May 12, 2023
1 parent 6c134ed commit c1c8a84
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
6 changes: 1 addition & 5 deletions nebari_workflow_controller/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
get_container_keep_portions,
get_keycloak_user,
get_spec_keep_portions,
get_spec_to_container_portions,
get_user_pod_spec,
mutate_template,
process_unhandled_exception,
Expand Down Expand Up @@ -144,9 +143,6 @@ def mutate(request=Body(...)):

container_keep_portions = get_container_keep_portions(user_pod_spec, api)
spec_keep_portions = get_spec_keep_portions(user_pod_spec, api)
spec_to_container_portions = get_spec_to_container_portions(
user_pod_spec, api
)

if spec["kind"] == "Workflow":
templates = modified_spec["spec"]["templates"]
Expand All @@ -160,7 +156,7 @@ def mutate(request=Body(...)):
container_keep_portions,
spec_keep_portions,
template,
spec_to_container_portions,
# spec_to_template_portions,
)

patch = jsonpatch.JsonPatch.from_diff(spec, modified_spec)
Expand Down
7 changes: 7 additions & 0 deletions nebari_workflow_controller/nwc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""This module provides an alias (nwc) for nebari-workflow-controller.
E.g. "python -m nwc" or "python -m nebari_workflow_controller" will start nebari-workflow-controller.
"""
from nebari_workflow_controller.__main__ import main

if __name__ == "__main__":
main()
29 changes: 4 additions & 25 deletions nebari_workflow_controller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ def get_user_pod_spec(keycloak_user):
return jupyter_pod_spec


def get_spec_to_container_portions(user_pod_spec, api):
return [
(
api.sanitize_for_serialization(user_pod_spec.spec.node_selector),
"nodeSelector",
)
]


def get_spec_keep_portions(user_pod_spec, api):
return [
(
Expand All @@ -217,6 +208,10 @@ def get_spec_keep_portions(user_pod_spec, api):
],
"volumes",
),
(
api.sanitize_for_serialization(user_pod_spec.spec.node_selector),
"nodeSelector",
),
]


Expand Down Expand Up @@ -278,7 +273,6 @@ def mutate_template(
container_keep_portions,
spec_keep_portions,
template,
spec_to_container_portions=None,
):
for value, key in container_keep_portions:
if "container" not in template:
Expand Down Expand Up @@ -310,18 +304,3 @@ def mutate_template(
template[key] = value
else:
template[key] = value

if spec_to_container_portions:
for value, key in spec_to_container_portions:
if isinstance(value, dict):
if key in template["container"]:
recursive_dict_merge(template["container"][key], value)
else:
template["container"][key] = value
elif isinstance(value, list):
if key in template["container"]:
template["container"][key].append(value)
else:
template["container"][key] = value
else:
template["container"][key] = value
6 changes: 3 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ def test_mutate_check_content(
]:
assert volume in mutated_spec["spec"]["templates"][0]["volumes"]

assert mutated_spec["spec"]["templates"][0]["container"]["nodeSelector"] == {
assert mutated_spec["spec"]["templates"][0]["nodeSelector"] == {
"mylabel": "myValue",
"cloud.google.com/gke-nodepool": "user",
}

assert mutated_spec["spec"]["templates"][0]["container"]["resources"] == {
"requests": {"cpu": "3000m", "memory": "5368709120"},
"limits": {"cpu": "2", "memory": "8589934592"},
"requests": {"cpu": "1500m", "memory": "5368709120"},
"limits": {"cpu": "3000m", "memory": "8589934592"},
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ request:
args:
- conda run -n nebari-git-dask python script.py
resources:
requests:
limits:
cpu: '3000m'
nodeSelector:
mylabel: myValue
nodeSelector:
mylabel: myValue
entrypoint: argosay
uid: c1bba5c6-2189-41ff-9487-be504c04487b
userInfo:
Expand Down

0 comments on commit c1c8a84

Please sign in to comment.