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

fix duplicate env vars + ability to add custom address for scheduler #843

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 19 additions & 5 deletions dask_kubernetes/operator/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
from collections import defaultdict
from contextlib import suppress
from copy import deepcopy
from datetime import datetime
from uuid import uuid4

Expand Down Expand Up @@ -64,6 +65,17 @@ def _get_labels(meta):
}


def _consolidate_env_vars(existing_env_vars, additional_env_vars):
existing_env_names = {d["name"] for d in existing_env_vars}
additional_env_names = {d["name"] for d in additional_env_vars}

overlapping_env_names = existing_env_names.intersection(additional_env_names)

additional_env_vars_to_keep = [d for d in additional_env_vars if d["name"] not in overlapping_env_names]

return [*existing_env_vars, *additional_env_vars_to_keep]


def build_scheduler_deployment_spec(
cluster_name, namespace, pod_spec, annotations, labels
):
Expand Down Expand Up @@ -159,9 +171,9 @@ def build_worker_deployment_spec(
]
for i in range(len(deployment_spec["spec"]["template"]["spec"]["containers"])):
if "env" in deployment_spec["spec"]["template"]["spec"]["containers"][i]:
deployment_spec["spec"]["template"]["spec"]["containers"][i]["env"].extend(
env
)
existing_env_vars = deployment_spec["spec"]["template"]["spec"]["containers"][i]["env"]
all_env_vars = _consolidate_env_vars(existing_env_vars, env)
deployment_spec["spec"]["template"]["spec"]["containers"][i]["env"] = all_env_vars
else:
deployment_spec["spec"]["template"]["spec"]["containers"][i]["env"] = env
return deployment_spec
Expand Down Expand Up @@ -197,7 +209,9 @@ def build_job_pod_spec(job_name, cluster_name, namespace, spec, annotations, lab
]
for i in range(len(pod_spec["spec"]["containers"])):
if "env" in pod_spec["spec"]["containers"][i]:
pod_spec["spec"]["containers"][i]["env"].extend(env)
existing_env_vars = pod_spec["spec"]["template"]["spec"]["containers"][i]["env"]
all_env_vars = _consolidate_env_vars(existing_env_vars, env)
pod_spec["spec"]["containers"][i]["env"] = all_env_vars
else:
pod_spec["spec"]["containers"][i]["env"] = env
return pod_spec
Expand Down Expand Up @@ -581,7 +595,7 @@ async def daskworkergroup_replica_update(
namespace=namespace,
cluster_name=cluster_name,
uuid=uuid4().hex[:10],
pod_spec=worker_spec["spec"],
pod_spec=deepcopy(worker_spec["spec"]),
annotations=annotations,
labels=labels,
)
Expand Down
Loading