)

    start_pod = EksPodOperator(
        task_id="run_pod",
        pod_name="run_pod",
        cluster_name=CLUSTER_NAME,
        image="amazon/aws-cli:latest",
        cmds=["sh", "-c", "echo Test Airflow; date"],
        labels={"demo": "hello_world"},
        get_logs=True,
        # Delete the pod when it reaches its final state, or the execution is interrupted.
        is_delete_operator_pod=True,
    )

    # An Amazon EKS cluster can not be deleted with attached resources such as nodegroups or Fargate profiles.
    # Setting the `force` to `True` will delete any attached resources before deleting the cluster.
    delete_all = EksDeleteClusterOperator(
        task_id='delete_fargate_profile_and_cluster',
        cluster_name=CLUSTER_NAME,
        force_delete_compute=True,
    )

    await_delete_cluster = EksClusterStateSensor(
        task_id='wait_for_delete_cluster',
        cluster_name=CLUSTER_NAME,
        target_state=ClusterStates.NONEXISTENT,
    )

    (create_cluster_and_fargate_profile >> await_create_fargate_profile >>
     start_pod >> delete_all >> await_delete_cluster)
        is_delete_operator_pod=True,
    )

    delete_nodegroup = EksDeleteNodegroupOperator(
        task_id='delete_eks_nodegroup',
        cluster_name=CLUSTER_NAME,
        nodegroup_name=NODEGROUP_NAME,
    )

    await_delete_nodegroup = EksNodegroupStateSensor(
        task_id='wait_for_delete_nodegroup',
        cluster_name=CLUSTER_NAME,
        nodegroup_name=NODEGROUP_NAME,
        target_state=NodegroupStates.NONEXISTENT,
    )

    delete_cluster = EksDeleteClusterOperator(
        task_id='delete_eks_cluster',
        cluster_name=CLUSTER_NAME,
    )

    await_delete_cluster = EksClusterStateSensor(
        task_id='wait_for_delete_cluster',
        cluster_name=CLUSTER_NAME,
        target_state=ClusterStates.NONEXISTENT,
    )

    (create_cluster >> await_create_cluster >> create_nodegroup >>
     await_create_nodegroup >> start_pod >> delete_nodegroup >>
     await_delete_nodegroup >> delete_cluster >> await_delete_cluster)
        cluster_name=CLUSTER_NAME,
        pod_name="run_pod",
        image="amazon/aws-cli:latest",
        cmds=["sh", "-c", "echo Test Airflow; date"],
        labels={"demo": "hello_world"},
        get_logs=True,
        # Delete the pod when it reaches its final state, or the execution is interrupted.
        is_delete_operator_pod=True,
    )

    # [START howto_operator_eks_force_delete_cluster]
    # An Amazon EKS cluster can not be deleted with attached resources such as nodegroups or Fargate profiles.
    # Setting the `force` to `True` will delete any attached resources before deleting the cluster.
    delete_all = EksDeleteClusterOperator(
        task_id='delete_nodegroup_and_cluster',
        cluster_name=CLUSTER_NAME,
        force_delete_compute=True,
    )
    # [END howto_operator_eks_force_delete_cluster]

    await_delete_cluster = EksClusterStateSensor(
        task_id='wait_for_delete_cluster',
        cluster_name=CLUSTER_NAME,
        target_state=ClusterStates.NONEXISTENT,
    )

    (
        create_cluster_and_nodegroup
        >> await_create_nodegroup
        >> start_pod
        >> delete_all
        pod_name="run_pod",
        image="amazon/aws-cli:latest",
        cmds=["sh", "-c", "ls"],
        labels={"demo": "hello_world"},
        get_logs=True,
        # Delete the pod when it reaches its final state, or the execution is interrupted.
        is_delete_operator_pod=True,
    )

    delete_nodegroup = EksDeleteNodegroupOperator(
        task_id='delete_eks_nodegroup',
        nodegroup_name="{{ dag_run.conf['nodegroup_name'] }}",
    )

    await_delete_nodegroup = EksNodegroupStateSensor(
        task_id='wait_for_delete_nodegroup',
        nodegroup_name="{{ dag_run.conf['nodegroup_name'] }}",
        target_state=NodegroupStates.NONEXISTENT,
    )

    delete_cluster = EksDeleteClusterOperator(task_id='delete_eks_cluster', )

    await_delete_cluster = EksClusterStateSensor(
        task_id='wait_for_delete_cluster',
        target_state=ClusterStates.NONEXISTENT,
    )

    (create_cluster >> await_create_cluster >> create_nodegroup >>
     await_create_nodegroup >> start_pod >> delete_nodegroup >>
     await_delete_nodegroup >> delete_cluster >> await_delete_cluster)
Exemple #5
0
        task_id='wait_for_create_nodegroup',
        nodegroup_name=NODEGROUP_NAME,
        target_state=NodegroupStates.ACTIVE,
    )

    start_pod = EksPodOperator(
        task_id="run_pod",
        pod_name="run_pod",
        image="amazon/aws-cli:latest",
        cmds=["sh", "-c", "echo Test Airflow; date"],
        labels={"demo": "hello_world"},
        get_logs=True,
        # Delete the pod when it reaches its final state, or the execution is interrupted.
        is_delete_operator_pod=True,
    )

    # [START howto_operator_eks_force_delete_cluster]
    # An Amazon EKS cluster can not be deleted with attached resources such as nodegroups or Fargate profiles.
    # Setting the `force` to `True` will delete any attached resources before deleting the cluster.
    delete_all = EksDeleteClusterOperator(
        task_id='delete_nodegroup_and_cluster', force_delete_compute=True)
    # [END howto_operator_eks_force_delete_cluster]

    await_delete_cluster = EksClusterStateSensor(
        task_id='wait_for_delete_cluster',
        target_state=ClusterStates.NONEXISTENT,
    )

    (create_cluster_and_nodegroup >> await_create_nodegroup >> start_pod >>
     delete_all >> await_delete_cluster)
Exemple #6
0
    await_create_fargate_profile = EksFargateProfileStateSensor(
        task_id='wait_for_create_fargate_profile',
        fargate_profile_name=FARGATE_PROFILE_NAME,
        target_state=FargateProfileStates.ACTIVE,
    )

    start_pod = EksPodOperator(
        task_id="run_pod",
        pod_name="run_pod",
        image="amazon/aws-cli:latest",
        cmds=["sh", "-c", "echo Test Airflow; date"],
        labels={"demo": "hello_world"},
        get_logs=True,
        # Delete the pod when it reaches its final state, or the execution is interrupted.
        is_delete_operator_pod=True,
    )

    # An Amazon EKS cluster can not be deleted with attached resources such as nodegroups or Fargate profiles.
    # Setting the `force` to `True` will delete any attached resources before deleting the cluster.
    delete_all = EksDeleteClusterOperator(
        task_id='delete_fargate_profile_and_cluster',
        force_delete_compute=True)

    await_delete_cluster = EksClusterStateSensor(
        task_id='wait_for_delete_cluster',
        target_state=ClusterStates.NONEXISTENT,
    )

    (create_cluster_and_fargate_profile >> await_create_fargate_profile >>
     start_pod >> delete_all >> await_delete_cluster)