Ejemplo n.º 1
0
        preferred_during_scheduling_ignored_during_execution=[
            k8s.V1PreferredSchedulingTerm(
                weight=1,
                preference=k8s.V1NodeSelectorTerm(match_expressions=[
                    k8s.V1NodeSelectorRequirement(
                        key="disktype", operator="in", values=["ssd"])
                ]),
            )
        ]),
    pod_affinity=k8s.V1PodAffinity(
        required_during_scheduling_ignored_during_execution=[
            k8s.V1WeightedPodAffinityTerm(
                weight=1,
                pod_affinity_term=k8s.V1PodAffinityTerm(
                    label_selector=k8s.V1LabelSelector(match_expressions=[
                        k8s.V1LabelSelectorRequirement(
                            key="security", operator="In", values="S1")
                    ]),
                    topology_key="failure-domain.beta.kubernetes.io/zone",
                ),
            )
        ]),
)

tolerations = [k8s.V1Toleration(key="key", operator="Equal", value="value")]

# [END howto_operator_k8s_cluster_resources]

default_args = {
    "owner": "airflow",
}
                image=f"{worker_container_repository}:{worker_container_tag}"),
        ]))
    }

    @task(executor_config=kube_exec_config_special)
    def base_image_override_task():
        print_stuff()

    base_image_task = base_image_override_task()

    # Use k8s_client.V1Affinity to define node affinity
    k8s_affinity = k8s.V1Affinity(pod_anti_affinity=k8s.V1PodAntiAffinity(
        required_during_scheduling_ignored_during_execution=[
            k8s.V1PodAffinityTerm(
                label_selector=k8s.V1LabelSelector(match_expressions=[
                    k8s.V1LabelSelectorRequirement(
                        key='app', operator='In', values=['airflow'])
                ]),
                topology_key='kubernetes.io/hostname',
            )
        ]))

    # Use k8s_client.V1Toleration to define node tolerations
    k8s_tolerations = [
        k8s.V1Toleration(key='dedicated', operator='Equal', value='airflow')
    ]

    # Use k8s_client.V1ResourceRequirements to define resource limits
    k8s_resource_requirements = k8s.V1ResourceRequirements(
        requests={'memory': '512Mi'}, limits={'memory': '512Mi'})

    kube_exec_config_resource_limits = {