From e54fba5b479e36ecad6afb8d3920a534af6e6135 Mon Sep 17 00:00:00 2001 From: Quentin Lemaire Date: Thu, 16 Jan 2020 17:57:48 +0100 Subject: [PATCH] [AIRFLOW-5501] Make default `in_cluster` value in KubernetesPodOperator respect config (#6124) The default value of the parameter in_cluster of the kube_client.get_kube_client function is in_cluster=conf.getboolean('kubernetes', 'in_cluster'). Therefore, the expected behavior is that when, in_cluster is not set, it takes the value in the configuration file. However, the default value of in_cluster in KubernetesPodOperator.py is False and in_cluster is passed as a parameter when calling the kube_client.get_kube_client function. Therefore, it changes the expecting behavior by overwritting the default value. When in_cluster is not set when initializing KubernetesPodOperator, the value of in_cluster in kube_client.get_kube_client is False and not the value which is in the configuration file. Therefore, the default value of in_cluster in KubernetesPodOperator has been changed to None and will not be passed to get_kube_client if it is not overwritten so that it takes the configuration value as a default value. Co-authored-by: Ash Berlin-Taylor --- airflow/contrib/operators/kubernetes_pod_operator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/airflow/contrib/operators/kubernetes_pod_operator.py b/airflow/contrib/operators/kubernetes_pod_operator.py index 34c7fc79c9914..981500d5e688a 100644 --- a/airflow/contrib/operators/kubernetes_pod_operator.py +++ b/airflow/contrib/operators/kubernetes_pod_operator.py @@ -147,7 +147,7 @@ def __init__(self, # pylint: disable=too-many-arguments,too-many-locals volumes: Optional[List[Volume]] = None, env_vars: Optional[Dict] = None, secrets: Optional[List[Secret]] = None, - in_cluster: bool = True, + in_cluster: Optional[bool] = None, cluster_context: Optional[str] = None, labels: Optional[Dict] = None, startup_timeout_seconds: int = 120, @@ -215,9 +215,13 @@ def __init__(self, # pylint: disable=too-many-arguments,too-many-locals def execute(self, context): try: - client = kube_client.get_kube_client(in_cluster=self.in_cluster, - cluster_context=self.cluster_context, - config_file=self.config_file) + if self.in_cluster is not None: + client = kube_client.get_kube_client(in_cluster=self.in_cluster, + cluster_context=self.cluster_context, + config_file=self.config_file) + else: + client = kube_client.get_kube_client(cluster_context=self.cluster_context, + config_file=self.config_file) # Add Airflow Version to the label # And a label to identify that pod is launched by KubernetesPodOperator