diff --git a/airflow/providers/amazon/aws/example_dags/example_eks_templated.py b/airflow/providers/amazon/aws/example_dags/example_eks_templated.py index 67f426d77c083..330c3b472f53f 100644 --- a/airflow/providers/amazon/aws/example_dags/example_eks_templated.py +++ b/airflow/providers/amazon/aws/example_dags/example_eks_templated.py @@ -85,6 +85,7 @@ start_pod = EKSPodOperator( task_id="run_pod", + pod_name="start_pod", cluster_name="{{ dag_run.conf['cluster_name'] }}", image="amazon/aws-cli:latest", cmds=["sh", "-c", "ls"], diff --git a/airflow/providers/amazon/aws/example_dags/example_eks_using_defaults.py b/airflow/providers/amazon/aws/example_dags/example_eks_using_defaults.py index 63aa853344882..12a80fb4e6e27 100644 --- a/airflow/providers/amazon/aws/example_dags/example_eks_using_defaults.py +++ b/airflow/providers/amazon/aws/example_dags/example_eks_using_defaults.py @@ -71,6 +71,7 @@ start_pod = EKSPodOperator( task_id="run_pod", + pod_name="run_pod", cluster_name=CLUSTER_NAME, image="amazon/aws-cli:latest", cmds=["sh", "-c", "ls"], diff --git a/airflow/providers/amazon/aws/example_dags/example_eks_with_nodegroups.py b/airflow/providers/amazon/aws/example_dags/example_eks_with_nodegroups.py index 4e5488522e6ed..89f94ed0baefc 100644 --- a/airflow/providers/amazon/aws/example_dags/example_eks_with_nodegroups.py +++ b/airflow/providers/amazon/aws/example_dags/example_eks_with_nodegroups.py @@ -86,6 +86,7 @@ # [START howto_operator_eks_pod_operator] start_pod = EKSPodOperator( task_id="run_pod", + pod_name="run_pod", cluster_name=CLUSTER_NAME, image="amazon/aws-cli:latest", cmds=["sh", "-c", "ls"], diff --git a/airflow/providers/amazon/aws/operators/eks.py b/airflow/providers/amazon/aws/operators/eks.py index 9fce83f870ea3..35f958e123606 100644 --- a/airflow/providers/amazon/aws/operators/eks.py +++ b/airflow/providers/amazon/aws/operators/eks.py @@ -21,6 +21,7 @@ from time import sleep from typing import Dict, Iterable, List, Optional +from airflow import AirflowException from airflow.models import BaseOperator from airflow.providers.amazon.aws.hooks.eks import ClusterStates, EKSHook from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator @@ -414,12 +415,21 @@ def __init__( in_cluster: bool = False, namespace: str = DEFAULT_NAMESPACE_NAME, pod_context: str = None, - pod_name: str = DEFAULT_POD_NAME, + pod_name: str = None, pod_username: str = None, aws_conn_id: str = DEFAULT_CONN_ID, region: Optional[str] = None, **kwargs, ) -> None: + if pod_name is None: + warnings.warn( + "Default value of pod name is deprecated. " + "We recommend that you pass pod name explicitly. ", + DeprecationWarning, + stacklevel=2, + ) + pod_name = DEFAULT_POD_NAME + self.cluster_name = cluster_name self.in_cluster = in_cluster self.namespace = namespace @@ -446,6 +456,10 @@ def __init__( DeprecationWarning, stacklevel=2, ) + # There is no need to manage the kube_config file, as it will be generated automatically. + # All Kubernetes parameters (except config_file) are also valid for the EKSPodOperator. + if self.config_file: + raise AirflowException("The config_file is not an allowed parameter for the EKSPodOperator.") def execute(self, context): eks_hook = EKSHook( diff --git a/tests/providers/amazon/aws/operators/test_eks.py b/tests/providers/amazon/aws/operators/test_eks.py index 864bb673f599c..87e5a2a06ed26 100644 --- a/tests/providers/amazon/aws/operators/test_eks.py +++ b/tests/providers/amazon/aws/operators/test_eks.py @@ -174,6 +174,7 @@ def test_existing_nodegroup( op = EKSPodOperator( task_id="run_pod", + pod_name="run_pod", cluster_name=CLUSTER_NAME, image="amazon/aws-cli:latest", cmds=["sh", "-c", "ls"],