Exemplo n.º 1
0
def test_populate_worker_pod_yaml():
    environment = DaskKubernetesEnvironment()

    file_path = os.path.dirname(
        prefect.environments.execution.dask.k8s.__file__)

    with open(path.join(file_path, "worker_pod.yaml")) as pod_file:
        pod = yaml.safe_load(pod_file)

    with set_temporary_config({
            "cloud.graphql": "gql_test",
            "cloud.auth_token": "auth_test",
            "logging.extra_loggers": ["test_logger"],
    }):
        with prefect.context(flow_run_id="id_test", image="my_image"):
            yaml_obj = environment._populate_worker_pod_yaml(yaml_obj=pod)

    assert (yaml_obj["metadata"]["labels"]["prefect.io/identifier"] ==
            environment.identifier_label)
    assert yaml_obj["metadata"]["labels"][
        "prefect.io/flow_run_id"] == "id_test"

    env = yaml_obj["spec"]["containers"][0]["env"]

    assert env[0]["value"] == "gql_test"
    assert env[1]["value"] == "auth_test"
    assert env[2]["value"] == "id_test"
    assert (
        env[10]["value"] ==
        "['test_logger', 'dask_kubernetes.core', 'distributed.deploy.adaptive']"
    )

    assert yaml_obj["spec"]["containers"][0]["image"] == "my_image"
Exemplo n.º 2
0
def test_populate_worker_pod_yaml_with_image_pull_secret():
    environment = DaskKubernetesEnvironment(image_pull_secret="mysecret")

    file_path = os.path.dirname(prefect.environments.execution.dask.k8s.__file__)

    with open(path.join(file_path, "worker_pod.yaml")) as pod_file:
        pod = yaml.safe_load(pod_file)

    with set_temporary_config(
        {"cloud.graphql": "gql_test", "cloud.auth_token": "auth_test"}
    ):
        with prefect.context(
            flow_run_id="id_test", image="my_image", namespace="foo-man"
        ):
            yaml_obj = environment._populate_worker_pod_yaml(yaml_obj=pod)

    yaml_obj["spec"]["imagePullSecrets"][0] == dict(name="mysecret")