You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ds...@apache.org on 2022/11/06 04:18:35 UTC
[airflow] branch main updated: KPO should use hook's get namespace method to get namespace (#27516)
This is an automated email from the ASF dual-hosted git repository.
dstandish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 20ecefa416 KPO should use hook's get namespace method to get namespace (#27516)
20ecefa416 is described below
commit 20ecefa416640bc9a3afc2c86848ca2e2436f6a4
Author: Daniel Standish <15...@users.noreply.github.com>
AuthorDate: Sat Nov 5 21:18:21 2022 -0700
KPO should use hook's get namespace method to get namespace (#27516)
Recently hook was updated to allow non-prefixed extra fields. So we need to check non-prefixed also. Best to use the hook's "get namespace" method. But the public one has a problem; it defaults to `default`, so we don't know if it was set to that intentionally. So we use the "protected" method `_get_namespace`, which doesn't return a default. This allows us, in this case to check if we can derive from cluster, and only _then_ default to `default`.
In 6.0, get_namespace will have the correct behavior, and we'll update this again to use it instead.
---
airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
index 666eb23e96..bf9d229486 100644
--- a/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
@@ -571,7 +571,9 @@ class KubernetesPodOperator(BaseOperator):
pod.metadata.name = PodGenerator.make_unique_pod_id(pod.metadata.name)
if not pod.metadata.namespace:
- hook_namespace = self.hook.conn_extras.get("extra__kubernetes__namespace")
+ # todo: replace with call to `hook.get_namespace` in 6.0, when it doesn't default to `default`.
+ # if namespace not actually defined in hook, we want to check k8s if in cluster
+ hook_namespace = self.hook._get_namespace()
pod_namespace = self.namespace or hook_namespace or self._incluster_namespace or "default"
pod.metadata.namespace = pod_namespace