Пример #1
0
with DAG(
        dag_id='to-publish-manuals-templated',
        schedule_interval=None,
        start_date=days_ago(2),
        max_active_runs=1,
        tags=['example', 'templated'],
        # render_template_as_native_obj=True is what converts the Jinja to Python objects, instead of a string.
        render_template_as_native_obj=True,
) as dag:

    # Create an Amazon EKS Cluster control plane without attaching a compute service.
    create_cluster = EKSCreateClusterOperator(
        task_id='create_eks_cluster',
        compute=None,
        cluster_name="{{ dag_run.conf['cluster_name'] }}",
        cluster_role_arn="{{ dag_run.conf['cluster_role_arn'] }}",
        resources_vpc_config="{{ dag_run.conf['resources_vpc_config'] }}",
    )

    await_create_cluster = EKSClusterStateSensor(
        task_id='wait_for_create_cluster',
        cluster_name="{{ dag_run.conf['cluster_name'] }}",
        target_state=ClusterStates.ACTIVE,
    )

    create_nodegroup = EKSCreateNodegroupOperator(
        task_id='create_eks_nodegroup',
        cluster_name="{{ dag_run.conf['cluster_name'] }}",
        nodegroup_name="{{ dag_run.conf['nodegroup_name'] }}",
        nodegroup_subnets="{{ dag_run.conf['nodegroup_subnets'] }}",
    dag_id='example_eks_using_defaults_dag',
    default_args={'cluster_name': CLUSTER_NAME},
    schedule_interval=None,
    start_date=datetime(2021, 1, 1),
    max_active_runs=1,
    tags=['example'],
) as dag:

    # [START howto_operator_eks_create_cluster_with_nodegroup]
    # Create an Amazon EKS cluster control plane and an EKS nodegroup compute platform in one step.
    create_cluster_and_nodegroup = EKSCreateClusterOperator(
        task_id='create_eks_cluster_and_nodegroup',
        nodegroup_name=NODEGROUP_NAME,
        cluster_role_arn=ROLE_ARN,
        nodegroup_role_arn=ROLE_ARN,
        # Opting to use the same ARN for the cluster and the nodegroup here,
        # but a different ARN could be configured and passed if desired.
        resources_vpc_config=VPC_CONFIG,
        # Compute defaults to 'nodegroup' but is called out here for the purposed of the example.
        compute='nodegroup',
    )
    # [END howto_operator_eks_create_cluster_with_nodegroup]

    await_create_nodegroup = EKSNodegroupStateSensor(
        task_id='wait_for_create_nodegroup',
        nodegroup_name=NODEGROUP_NAME,
        target_state=NodegroupStates.ACTIVE,
    )

    start_pod = EKSPodOperator(
        task_id="run_pod",
Пример #3
0

with DAG(
    dag_id='example_eks_with_fargate_profile_dag',
    default_args={'cluster_name': CLUSTER_NAME},
    schedule_interval=None,
    start_date=datetime(2021, 1, 1),
    catchup=False,
    max_active_runs=1,
    tags=['example'],
) as dag:

    # Create an Amazon EKS Cluster control plane without attaching a compute service.
    create_cluster = EKSCreateClusterOperator(
        task_id='create_eks_cluster',
        cluster_role_arn=ROLE_ARN,
        resources_vpc_config=VPC_CONFIG,
        compute=None,
    )

    await_create_cluster = EKSClusterStateSensor(
        task_id='wait_for_create_cluster',
        target_state=ClusterStates.ACTIVE,
    )

    # [START howto_operator_eks_create_fargate_profile]
    create_fargate_profile = EKSCreateFargateProfileOperator(
        task_id='create_eks_fargate_profile',
        pod_execution_role_arn=ROLE_ARN,
        fargate_profile_name=FARGATE_PROFILE_NAME,
        selectors=SELECTORS,
    )
Пример #4
0
with DAG(
        dag_id='example-create-cluster-and-fargate-all-in-one',
        default_args={'cluster_name': CLUSTER_NAME},
        schedule_interval=None,
        start_date=datetime(2021, 1, 1),
        max_active_runs=1,
        tags=['example'],
) as dag:

    # [START howto_operator_eks_create_cluster_with_fargate_profile]
    # Create an Amazon EKS cluster control plane and an AWS Fargate compute platform in one step.
    create_cluster_and_fargate_profile = EKSCreateClusterOperator(
        task_id='create_eks_cluster_and_fargate_profile',
        cluster_role_arn=ROLE_ARN,
        resources_vpc_config=VPC_CONFIG,
        compute='fargate',
        fargate_profile_name=FARGATE_PROFILE_NAME,
        # Opting to use the same ARN for the cluster and the pod here,
        # but a different ARN could be configured and passed if desired.
        fargate_pod_execution_role_arn=ROLE_ARN,
    )
    # [END howto_operator_eks_create_cluster_with_fargate_profile]

    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",