Beispiel #1
0
def test_workspace_renders_from_helm_dagit(template: HelmTemplate):
    servers = [
        Server(host="another-deployment-one", port=4000),
        Server(host="another-deployment-two", port=4001),
        Server(host="another-deployment-three", port=4002),
    ]
    helm_values = DagsterHelmValues.construct(
        dagit=Dagit.construct(
            workspace=Workspace(enabled=True, servers=servers)),
        dagsterUserDeployments=UserDeployments(
            enabled=True,
            enableSubchart=True,
            deployments=[
                create_simple_user_deployment("deployment-one"),
                create_simple_user_deployment("deployment-two"),
            ],
        ),
    )

    workspace_templates = template.render(helm_values)

    assert len(workspace_templates) == 1

    workspace_template = workspace_templates[0]

    workspace = yaml.full_load(workspace_template.data["workspace.yaml"])
    grpc_servers = workspace["load_from"]

    assert len(grpc_servers) == len(servers)

    for grpc_server, server in zip(grpc_servers, servers):
        assert grpc_server["grpc_server"]["host"] == server.host
        assert grpc_server["grpc_server"]["port"] == server.port
        assert grpc_server["grpc_server"]["location_name"] == server.host
Beispiel #2
0
def test_ingress_read_only(template: HelmTemplate):
    helm_values = DagsterHelmValues.construct(
        ingress=Ingress.construct(
            enabled=True,
            dagit=DagitIngressConfiguration.construct(
                host="foobar.com",
                path="bing",
                precedingPaths=[
                    IngressPath(path="/*",
                                serviceName="ssl-redirect",
                                servicePort="use-annotion")
                ],
            ),
            readOnlyDagit=DagitIngressConfiguration.construct(
                host="dagster.io",
                succeedingPaths=[
                    IngressPath(path="/*",
                                serviceName="ssl-redirect",
                                servicePort="use-annotion")
                ],
            ),
        ),
        dagit=Dagit.construct(enableReadOnly=True),
    )

    ingress_template = template.render(helm_values)
    assert len(ingress_template) == 1
    ingress = ingress_template[0]

    assert len(ingress.spec.rules) == 2
    assert [rule.host
            for rule in ingress.spec.rules] == ["foobar.com", "dagster.io"]
Beispiel #3
0
def test_dagit_db_statement_timeout(deployment_template: HelmTemplate):
    db_statement_timeout_ms = 9000
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        dbStatementTimeout=db_statement_timeout_ms))

    dagit_deployments = deployment_template.render(helm_values)
    command = " ".join(
        dagit_deployments[0].spec.template.spec.containers[0].command)

    assert f"--db-statement-timeout {db_statement_timeout_ms}" in command
Beispiel #4
0
def test_ingress_tls(template_function, output, model, api_version):
    template = template_function(output, model)
    dagit_host = "dagit.com"
    dagit_readonly_host = "dagit-readonly.com"
    flower_host = "flower.com"

    dagit_tls_secret_name = "dagit_tls_secret_name"
    dagit_readonly_tls_secret_name = "dagit_readonly_tls_secret_name"
    flower_tls_secret_name = "flower_tls_secret_name"

    helm_values = DagsterHelmValues.construct(
        ingress=Ingress.construct(
            enabled=True,
            apiVersion=api_version,
            dagit=DagitIngressConfiguration.construct(
                host=dagit_host,
                pathType=IngressPathType.IMPLEMENTATION_SPECIFIC,
                tls=IngressTLSConfiguration(enabled=True, secretName=dagit_tls_secret_name),
            ),
            readOnlyDagit=DagitIngressConfiguration.construct(
                host=dagit_readonly_host,
                pathType=IngressPathType.IMPLEMENTATION_SPECIFIC,
                tls=IngressTLSConfiguration(
                    enabled=True, secretName=dagit_readonly_tls_secret_name
                ),
            ),
            flower=FlowerIngressConfiguration.construct(
                host=flower_host,
                pathType=IngressPathType.IMPLEMENTATION_SPECIFIC,
                tls=IngressTLSConfiguration(enabled=True, secretName=flower_tls_secret_name),
            ),
        ),
        dagit=Dagit.construct(enableReadOnly=True),
    )

    [ingress] = template.render(helm_values)

    assert len(ingress.spec.tls) == 3

    dagit_tls = ingress.spec.tls[0]
    assert len(dagit_tls.hosts) == 1
    assert dagit_tls.hosts[0] == dagit_host
    assert dagit_tls.secret_name == dagit_tls_secret_name

    dagit_readonly_tls = ingress.spec.tls[1]
    assert len(dagit_readonly_tls.hosts) == 1
    assert dagit_readonly_tls.hosts[0] == dagit_readonly_host
    assert dagit_readonly_tls.secret_name == dagit_readonly_tls_secret_name

    flower_tls = ingress.spec.tls[2]
    assert len(flower_tls.hosts) == 1
    assert flower_tls.hosts[0] == flower_host
    assert flower_tls.secret_name == flower_tls_secret_name
Beispiel #5
0
def test_startup_probe_enabled(template: HelmTemplate, enabled: bool):
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        startupProbe=kubernetes.StartupProbe(enabled=enabled)))

    dagit = template.render(helm_values)
    assert len(dagit) == 1
    dagit = dagit[0]

    assert len(dagit.spec.template.spec.containers) == 1
    container = dagit.spec.template.spec.containers[0]

    assert (container.startup_probe is not None) == enabled
Beispiel #6
0
def test_readiness_probe(deployment_template: HelmTemplate):
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct())

    dagit = deployment_template.render(helm_values)
    assert len(dagit) == 1
    dagit = dagit[0]

    assert len(dagit.spec.template.spec.containers) == 1
    container = dagit.spec.template.spec.containers[0]

    assert container.startup_probe is None
    assert container.liveness_probe is None
    assert container.readiness_probe is not None
Beispiel #7
0
def test_dagit_labels(deployment_template: HelmTemplate):
    deployment_labels = {"deployment_label": "label"}
    pod_labels = {"pod_label": "label"}
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        deploymentLabels=deployment_labels,
        labels=pod_labels,
    ))

    [dagit_deployment] = deployment_template.render(helm_values)

    assert set(deployment_labels.items()).issubset(
        dagit_deployment.metadata.labels.items())
    assert set(pod_labels.items()).issubset(
        dagit_deployment.spec.template.metadata.labels.items())
Beispiel #8
0
def test_dagit_service_read_only(service_template):
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        enableReadOnly=True))
    dagit_template = service_template.render(helm_values)

    assert len(dagit_template) == 2
    assert [dagit.metadata.name for dagit in dagit_template] == [
        "release-name-dagit",
        "release-name-dagit-read-only",
    ]
    assert [dagit.spec.selector["component"] for dagit in dagit_template] == [
        "dagit",
        "dagit-read-only",
    ]
Beispiel #9
0
def test_ingress_tls(template: HelmTemplate):
    dagit_host = "dagit.com"
    dagit_readonly_host = "dagit-readonly.com"
    flower_host = "flower.com"

    dagit_tls_secret_name = "dagit_tls_secret_name"
    dagit_readonly_tls_secret_name = "dagit_readonly_tls_secret_name"
    flower_tls_secret_name = "flower_tls_secret_name"

    helm_values = DagsterHelmValues.construct(
        ingress=Ingress.construct(
            enabled=True,
            dagit=DagitIngressConfiguration.construct(
                host=dagit_host,
                tls=IngressTLSConfiguration(enabled=True,
                                            secretName=dagit_tls_secret_name),
            ),
            readOnlyDagit=DagitIngressConfiguration.construct(
                host=dagit_readonly_host,
                tls=IngressTLSConfiguration(
                    enabled=True, secretName=dagit_readonly_tls_secret_name),
            ),
            flower=FlowerIngressConfiguration.construct(
                host=flower_host,
                tls=IngressTLSConfiguration(enabled=True,
                                            secretName=flower_tls_secret_name),
            ),
        ),
        dagit=Dagit.construct(enableReadOnly=True),
    )

    [ingress] = template.render(helm_values)

    assert len(ingress.spec.tls) == 3

    dagit_tls = ingress.spec.tls[0]
    assert len(dagit_tls.hosts) == 1
    assert dagit_tls.hosts[0] == dagit_host
    assert dagit_tls.secret_name == dagit_tls_secret_name

    dagit_readonly_tls = ingress.spec.tls[1]
    assert len(dagit_readonly_tls.hosts) == 1
    assert dagit_readonly_tls.hosts[0] == dagit_readonly_host
    assert dagit_readonly_tls.secret_name == dagit_readonly_tls_secret_name

    flower_tls = ingress.spec.tls[2]
    assert len(flower_tls.hosts) == 1
    assert flower_tls.hosts[0] == flower_host
    assert flower_tls.secret_name == flower_tls_secret_name
Beispiel #10
0
def test_dagit_image_tag(deployment_template: HelmTemplate):
    repository = "repository"
    tag = "tag"
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        image=kubernetes.Image.construct(repository=repository, tag=tag)))

    dagit_deployments = deployment_template.render(helm_values)

    assert len(dagit_deployments) == 1

    image = dagit_deployments[0].spec.template.spec.containers[0].image
    image_name, image_tag = image.split(":")

    assert image_name == repository
    assert image_tag == tag
Beispiel #11
0
def test_dagit_default_image_tag_is_chart_version(
        deployment_template: HelmTemplate, enable_read_only: bool,
        chart_version: str):
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        enableReadOnly=enable_read_only))

    dagit_deployments = deployment_template.render(helm_values,
                                                   chart_version=chart_version)

    assert len(dagit_deployments) == 1 + int(enable_read_only)

    for dagit_deployment in dagit_deployments:
        image = dagit_deployment.spec.template.spec.containers[0].image
        _, image_tag = image.split(":")

        assert image_tag == chart_version
Beispiel #12
0
def test_dagit_port(deployment_template: HelmTemplate, service_port: int):
    helm_values = DagsterHelmValues.construct(
        dagit=Dagit.construct(service=kubernetes.Service(
            type="ClusterIP",
            port=service_port,
        ), ))

    dagit_template = deployment_template.render(helm_values)

    # Make sure dagit will start up serving the correct port
    dagit_command = "".join(
        dagit_template[0].spec.template.spec.containers[0].command)
    port_arg = f"-p {helm_values.dagit.service.port}"
    assert port_arg in dagit_command

    # Make sure k8s will open the correct port
    k8s_port = dagit_template[0].spec.template.spec.containers[0].ports[
        0].container_port
    assert k8s_port == service_port
Beispiel #13
0
def test_ingress_read_only(template_function, output, model, api_version):
    template = template_function(output, model)
    helm_values = DagsterHelmValues.construct(
        ingress=Ingress.construct(
            enabled=True,
            apiVersion=api_version,
            dagit=DagitIngressConfiguration.construct(
                host="foobar.com",
                path="bing",
                pathType=IngressPathType.IMPLEMENTATION_SPECIFIC,
                precedingPaths=[
                    IngressPath(
                        path="/*",
                        pathType=IngressPathType.IMPLEMENTATION_SPECIFIC,
                        serviceName="ssl-redirect",
                        servicePort="use-annotion",
                    )
                ],
            ),
            readOnlyDagit=DagitIngressConfiguration.construct(
                host="dagster.io",
                succeedingPaths=[
                    IngressPath(
                        path="/*",
                        pathType=IngressPathType.IMPLEMENTATION_SPECIFIC,
                        serviceName="ssl-redirect",
                        servicePort="use-annotion",
                    )
                ],
            ),
        ),
        dagit=Dagit.construct(enableReadOnly=True),
    )

    ingress_template = template.render(helm_values)
    assert len(ingress_template) == 1
    ingress = ingress_template[0]

    assert len(ingress.spec.rules) == 2
    assert [rule.host for rule in ingress.spec.rules] == ["foobar.com", "dagster.io"]
Beispiel #14
0
def test_workspace_renders_empty(template: HelmTemplate):
    servers: List[Server] = []
    helm_values = DagsterHelmValues.construct(
        dagit=Dagit.construct(
            workspace=Workspace(enabled=True, servers=servers)),
        dagsterUserDeployments=UserDeployments(
            enabled=True,
            enableSubchart=True,
            deployments=[],
        ),
    )

    workspace_templates = template.render(helm_values)

    assert len(workspace_templates) == 1

    workspace_template = workspace_templates[0]

    workspace = yaml.full_load(workspace_template.data["workspace.yaml"])
    grpc_servers = workspace["load_from"]

    assert len(grpc_servers) == len(servers)
Beispiel #15
0
def test_dagit_read_only_enabled(deployment_template: HelmTemplate):
    helm_values = DagsterHelmValues.construct(dagit=Dagit.construct(
        enableReadOnly=True))

    dagit_template = deployment_template.render(helm_values)

    assert len(dagit_template) == 2
    assert [
        "--read-only"
        in "".join(dagit.spec.template.spec.containers[0].command)
        for dagit in dagit_template
    ] == [False, True]
    assert [dagit.metadata.name for dagit in dagit_template] == [
        "release-name-dagit",
        "release-name-dagit-read-only",
    ]

    assert [
        dagit.spec.template.metadata.labels["component"]
        for dagit in dagit_template
    ] == [
        "dagit",
        "dagit-read-only",
    ]