From 9aa0804c54807f723f924ea2f56603fdef090255 Mon Sep 17 00:00:00 2001 From: Bernhard Stadlbauer <11799671+bstadlbauer@users.noreply.github.com> Date: Fri, 20 May 2022 12:31:23 +0200 Subject: [PATCH 1/4] Add note on test M1 incompatibility to docs --- doc/source/testing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/testing.rst b/doc/source/testing.rst index a2e6183c1..68f49cfbd 100644 --- a/doc/source/testing.rst +++ b/doc/source/testing.rst @@ -1,6 +1,8 @@ Testing ======= +.. warning:: Tests are not working on aarch64 (Apple M1) at the moment due to an architecture incompatibility between ``pytest-kind-control-plane`` and the docker image built from ``ci/Dockerfile``, similar to `this GitHub issue `_. + Running the test suite for ``dask-kubernetes`` doesn't require an existing Kubernetes cluster but does require `Docker `_, `kubectl `_ and `helm `_. From 6e99a8352d59d94d779e77d32c88d89570e44c37 Mon Sep 17 00:00:00 2001 From: Bernhard Stadlbauer <11799671+bstadlbauer@users.noreply.github.com> Date: Fri, 20 May 2022 13:34:58 +0000 Subject: [PATCH 2/4] Add tests to reproduce KubeCluster start failure with custom container name --- dask_kubernetes/classic/tests/test_async.py | 10 ++++++++++ dask_kubernetes/classic/tests/test_sync.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/dask_kubernetes/classic/tests/test_async.py b/dask_kubernetes/classic/tests/test_async.py index 5785d6dbd..f39021697 100644 --- a/dask_kubernetes/classic/tests/test_async.py +++ b/dask_kubernetes/classic/tests/test_async.py @@ -368,6 +368,16 @@ async def test_pod_template_from_conf(docker_image): ) +@pytest.mark.asyncio +async def test_pod_template_with_custom_container_name(docker_image): + container_name = "my-custom-container" + spec = {"spec": {"containers": [{"name": container_name, "image": docker_image}]}} + + with dask.config.set({"kubernetes.worker-template": spec}): + async with KubeCluster(**cluster_kwargs) as cluster: + assert cluster.pod_template.spec.containers[0].name == container_name + + @pytest.mark.asyncio async def test_constructor_parameters(k8s_cluster, pod_spec): env = {"FOO": "BAR", "A": 1} diff --git a/dask_kubernetes/classic/tests/test_sync.py b/dask_kubernetes/classic/tests/test_sync.py index f1d8428f6..3db05fe0f 100644 --- a/dask_kubernetes/classic/tests/test_sync.py +++ b/dask_kubernetes/classic/tests/test_sync.py @@ -249,6 +249,15 @@ def test_pod_template_from_conf(docker_image): ) +def test_pod_template_with_custom_container_name(docker_image): + container_name = "my-custom-container" + spec = {"spec": {"containers": [{"name": container_name, "image": docker_image}]}} + + with dask.config.set({"kubernetes.worker-template": spec}): + with KubeCluster() as cluster: + assert cluster.pod_template.spec.containers[0].name == container_name + + def test_bad_args(): with pytest.raises(FileNotFoundError) as info: KubeCluster("myfile.yaml") From bd1159224c0f5b339263e9aec9aafaba10257413 Mon Sep 17 00:00:00 2001 From: Bernhard Stadlbauer <11799671+bstadlbauer@users.noreply.github.com> Date: Fri, 20 May 2022 13:38:12 +0000 Subject: [PATCH 3/4] Fix container name when getting logs --- dask_kubernetes/classic/kubecluster.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dask_kubernetes/classic/kubecluster.py b/dask_kubernetes/classic/kubecluster.py index 0f63038c0..c7e16315a 100644 --- a/dask_kubernetes/classic/kubecluster.py +++ b/dask_kubernetes/classic/kubecluster.py @@ -16,7 +16,6 @@ import kubernetes_asyncio as kubernetes from kubernetes_asyncio.client.rest import ApiException -from ..constants import KUBECLUSTER_WORKER_CONTAINER_NAME from ..common.objects import ( make_pod_from_dict, make_service_from_dict, @@ -112,7 +111,7 @@ async def logs(self): log = await self.core_api.read_namespaced_pod_log( self._pod.metadata.name, self.namespace, - container=KUBECLUSTER_WORKER_CONTAINER_NAME, + container=self.pod_template.spec.containers[0].name, ) except ApiException as e: if "waiting to start" in str(e): From ade763469b526e7f1b933879ac3eefe5233398c1 Mon Sep 17 00:00:00 2001 From: Bernhard Stadlbauer <11799671+bstadlbauer@users.noreply.github.com> Date: Fri, 20 May 2022 13:40:02 +0000 Subject: [PATCH 4/4] Rename `KUBECLUSTER_WORKER_CONTAINER_NAME` to `KUBECLUSTER_CONTAINER_NAME` Done as the new name should be more accurate --- dask_kubernetes/classic/tests/test_async.py | 18 ++++++++---------- dask_kubernetes/classic/tests/test_sync.py | 18 ++++++++---------- dask_kubernetes/common/objects.py | 4 ++-- dask_kubernetes/common/tests/test_objects.py | 4 ++-- dask_kubernetes/constants.py | 2 +- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/dask_kubernetes/classic/tests/test_async.py b/dask_kubernetes/classic/tests/test_async.py index f39021697..33fb70219 100644 --- a/dask_kubernetes/classic/tests/test_async.py +++ b/dask_kubernetes/classic/tests/test_async.py @@ -24,7 +24,7 @@ from dask.utils import tmpfile from distributed.utils_test import captured_logger -from dask_kubernetes.constants import KUBECLUSTER_WORKER_CONTAINER_NAME +from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME TEST_DIR = os.path.abspath(os.path.join(__file__, "..")) CONFIG_DEMO = os.path.join(TEST_DIR, "config-demo.yaml") @@ -217,7 +217,7 @@ async def test_pod_from_yaml(k8s_cluster, docker_image): ], "image": docker_image, "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, @@ -262,7 +262,7 @@ async def test_pod_expand_env_vars(k8s_cluster, docker_image): ], "image": "${FOO_IMAGE}", "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, @@ -296,7 +296,7 @@ async def test_pod_template_dict(docker_image): "command": None, "image": docker_image, "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, @@ -336,7 +336,7 @@ async def test_pod_template_minimal_dict(k8s_cluster, docker_image): "command": None, "image": docker_image, "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] } @@ -354,9 +354,7 @@ async def test_pod_template_minimal_dict(k8s_cluster, docker_image): async def test_pod_template_from_conf(docker_image): spec = { "spec": { - "containers": [ - {"name": KUBECLUSTER_WORKER_CONTAINER_NAME, "image": docker_image} - ] + "containers": [{"name": KUBECLUSTER_CONTAINER_NAME, "image": docker_image}] } } @@ -364,7 +362,7 @@ async def test_pod_template_from_conf(docker_image): async with KubeCluster(**cluster_kwargs) as cluster: assert ( cluster.pod_template.spec.containers[0].name - == KUBECLUSTER_WORKER_CONTAINER_NAME + == KUBECLUSTER_CONTAINER_NAME ) @@ -577,7 +575,7 @@ async def test_automatic_startup(k8s_cluster, docker_image): "1", ], "image": docker_image, - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, diff --git a/dask_kubernetes/classic/tests/test_sync.py b/dask_kubernetes/classic/tests/test_sync.py index 3db05fe0f..5356cb102 100644 --- a/dask_kubernetes/classic/tests/test_sync.py +++ b/dask_kubernetes/classic/tests/test_sync.py @@ -9,7 +9,7 @@ from dask.utils import tmpfile from dask_kubernetes import KubeCluster, make_pod_spec -from dask_kubernetes.constants import KUBECLUSTER_WORKER_CONTAINER_NAME +from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME TEST_DIR = os.path.abspath(os.path.join(__file__, "..")) CONFIG_DEMO = os.path.join(TEST_DIR, "config-demo.yaml") @@ -100,7 +100,7 @@ def dont_test_pod_template_yaml(docker_image, loop): ], "image": docker_image, "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, @@ -146,7 +146,7 @@ def test_pod_template_yaml_expand_env_vars(docker_image, loop): ], "image": "${FOO_IMAGE}", "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, @@ -179,7 +179,7 @@ def test_pod_template_dict(docker_image, loop): "command": None, "image": docker_image, "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, @@ -218,7 +218,7 @@ def test_pod_template_minimal_dict(docker_image, loop): "command": None, "image": docker_image, "imagePullPolicy": "IfNotPresent", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] } @@ -235,9 +235,7 @@ def test_pod_template_minimal_dict(docker_image, loop): def test_pod_template_from_conf(docker_image): spec = { "spec": { - "containers": [ - {"name": KUBECLUSTER_WORKER_CONTAINER_NAME, "image": docker_image} - ] + "containers": [{"name": KUBECLUSTER_CONTAINER_NAME, "image": docker_image}] } } @@ -245,7 +243,7 @@ def test_pod_template_from_conf(docker_image): with KubeCluster() as cluster: assert ( cluster.pod_template.spec.containers[0].name - == KUBECLUSTER_WORKER_CONTAINER_NAME + == KUBECLUSTER_CONTAINER_NAME ) @@ -327,7 +325,7 @@ def test_automatic_startup(docker_image): "1", ], "image": docker_image, - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, } ] }, diff --git a/dask_kubernetes/common/objects.py b/dask_kubernetes/common/objects.py index bc5de03e3..fc8a3fbf8 100644 --- a/dask_kubernetes/common/objects.py +++ b/dask_kubernetes/common/objects.py @@ -8,7 +8,7 @@ from kubernetes.client.configuration import Configuration -from dask_kubernetes.constants import KUBECLUSTER_WORKER_CONTAINER_NAME +from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME _FakeResponse = namedtuple("_FakeResponse", ["data"]) @@ -193,7 +193,7 @@ def make_pod_spec( restart_policy="Never", containers=[ client.V1Container( - name=KUBECLUSTER_WORKER_CONTAINER_NAME, + name=KUBECLUSTER_CONTAINER_NAME, image=image, args=args, env=[client.V1EnvVar(name=k, value=v) for k, v in env.items()], diff --git a/dask_kubernetes/common/tests/test_objects.py b/dask_kubernetes/common/tests/test_objects.py index e057c8b18..72fac2da7 100644 --- a/dask_kubernetes/common/tests/test_objects.py +++ b/dask_kubernetes/common/tests/test_objects.py @@ -1,4 +1,4 @@ -from dask_kubernetes.constants import KUBECLUSTER_WORKER_CONTAINER_NAME +from dask_kubernetes.constants import KUBECLUSTER_CONTAINER_NAME from dask_kubernetes.common.objects import make_pod_from_dict @@ -16,7 +16,7 @@ def test_make_pod_from_dict(): "1", ], "image": "image-name", - "name": KUBECLUSTER_WORKER_CONTAINER_NAME, + "name": KUBECLUSTER_CONTAINER_NAME, "securityContext": { "capabilities": {"add": ["SYS_ADMIN"]}, "privileged": True, diff --git a/dask_kubernetes/constants.py b/dask_kubernetes/constants.py index 9555df4db..f22c804a5 100644 --- a/dask_kubernetes/constants.py +++ b/dask_kubernetes/constants.py @@ -1 +1 @@ -KUBECLUSTER_WORKER_CONTAINER_NAME = "dask-worker" +KUBECLUSTER_CONTAINER_NAME = "dask-container"