From 603f6ac9945a057369a7ffb835c152c80c9abbc4 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 29 Sep 2023 12:39:06 -0400 Subject: [PATCH] Avoid parsing resources when None (#824) --- .../operator/kubecluster/kubecluster.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/dask_kubernetes/operator/kubecluster/kubecluster.py b/dask_kubernetes/operator/kubecluster/kubecluster.py index 900387560..b9ea78888 100644 --- a/dask_kubernetes/operator/kubecluster/kubecluster.py +++ b/dask_kubernetes/operator/kubecluster/kubecluster.py @@ -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()) @@ -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