amoghrajesh commented on code in PR #61738:
URL: https://github.com/apache/airflow/pull/61738#discussion_r3000010874
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -818,6 +818,19 @@ def __init__(
self._event_polling_fallback = False
self._config_loaded = False
+ def _uses_exec_auth(self, kubeconfig_data: dict) -> bool:
+ """
+ Detect if kubeconfig uses exec-based authentication.
+
+ Exec plugins return short-lived tokens (EKS, GKE, etc).
+ """
+ users = kubeconfig_data.get("users", [])
+ for user in users:
+ user_auth = user.get("user", {})
+ if "exec" in user_auth:
+ return True
+ return False
Review Comment:
Still needs to be addressed.
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -846,50 +859,65 @@ async def _load_config(self):
self._config_loaded = True
return
- # If above block does not return, we are not in a cluster.
self._is_in_cluster = False
-
if self.config_dict:
self.log.debug(LOADING_KUBE_CONFIG_FILE_RESOURCE.format("config
dictionary"))
- await async_config.load_kube_config_from_dict(self.config_dict,
context=cluster_context)
- self._config_loaded = True
- return
+ await async_config.load_kube_config_from_dict(
+ self.config_dict,
+ context=cluster_context,
+ )
+
+ if not self._uses_exec_auth(self.config_dict):
+ self._config_loaded = True
+
+ return
if kubeconfig_path is not None:
self.log.debug("loading kube_config from: %s", kubeconfig_path)
+
await async_config.load_kube_config(
config_file=kubeconfig_path,
client_configuration=self.client_configuration,
context=cluster_context,
)
- self._config_loaded = True
- return
+ try:
+ import yaml
+
+ async with aiofiles.open(kubeconfig_path) as f:
+ content = await f.read()
+ data = yaml.safe_load(content)
+
+ if not self._uses_exec_auth(data):
+ self._config_loaded = True
+ except Exception:
+ pass
+
+ return
if kubeconfig is not None:
async with aiofiles.tempfile.NamedTemporaryFile() as temp_config:
- self.log.debug(
- "Reading kubernetes configuration file from connection "
- "object and writing temporary config file with its
content",
- )
if isinstance(kubeconfig, dict):
- self.log.debug(
- LOADING_KUBE_CONFIG_FILE_RESOURCE.format(
- "connection kube_config dictionary (serializing)"
- )
- )
- kubeconfig = json.dumps(kubeconfig)
- await temp_config.write(kubeconfig.encode())
+ kubeconfig_data = kubeconfig
+ kubeconfig_str = json.dumps(kubeconfig)
+ else:
+ kubeconfig_data = None
+ kubeconfig_str = kubeconfig
Review Comment:
Suggestion:
https://github.com/apache/airflow/pull/61738#discussion_r2999994916
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]