Skip to content

Commit

Permalink
Avoid parsing resources when None (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
droctothorpe authored Sep 29, 2023
1 parent 30234e3 commit 603f6ac
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions dask_kubernetes/operator/kubecluster/kubecluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(
"kubernetes.idle-timeout", override_with=idle_timeout
)

if self._custom_cluster_spec:
if self._custom_cluster_spec is not None:
if isinstance(self._custom_cluster_spec, str):
with open(self._custom_cluster_spec) as f:
self._custom_cluster_spec = yaml.safe_load(f.read())
Expand All @@ -232,21 +232,22 @@ def __init__(
if isinstance(self.worker_command, str):
self.worker_command = self.worker_command.split(" ")

try:
# Validate `resources` param is a dictionary whose
# keys must either be 'limits' or 'requests'
assert isinstance(
self.resources, dict
), f"resources must be dict type, found {type(resources)}"
for field in self.resources:
if field in ("limits", "requests"):
assert isinstance(
self.resources[field], dict
), f"key of '{field}' must be dict type"
else:
raise ValueError(f"resources has unknown field '{field}'")
except AssertionError as e:
raise TypeError from e
if self.resources is not None:
try:
# Validate `resources` param is a dictionary whose
# keys must either be 'limits' or 'requests'
assert isinstance(
self.resources, dict
), f"resources must be dict type, found {type(resources)}"
for field in self.resources:
if field in ("limits", "requests"):
assert isinstance(
self.resources[field], dict
), f"key of '{field}' must be dict type"
else:
raise ValueError(f"resources has unknown field '{field}'")
except AssertionError as e:
raise TypeError from e

name = name.format(
user=getpass.getuser(), uuid=str(uuid.uuid4())[:10], **os.environ
Expand Down

0 comments on commit 603f6ac

Please sign in to comment.