ZhaoMJ opened a new pull request, #65566:
URL: https://github.com/apache/airflow/pull/65566

   ## Summary
   
   When multiple deferrable `KubernetesPodOperator` tasks run concurrently on 
the same triggerer process, each task's `AsyncKubernetesHook` calls 
`load_kube_config_from_dict` (or `load_incluster_config`), which writes to the 
module-level **global** `kubernetes_asyncio` `Configuration` object. Because 
`load_kube_config_from_dict` is a coroutine with internal `await` points, two 
concurrent triggers for different clusters interleave and produce a **mixed 
global state** — e.g. cluster-A's server URL paired with cluster-B's bearer 
token. `_TimeoutAsyncK8sApiClient()` was then constructed with no 
`configuration=` argument, silently consuming whatever global state happened to 
be current.
   
   This manifests as intermittent 403 errors on long-running pods in 
cross-cluster setups: the API server receives a request from the wrong service 
account identity.
   
   Changes:
   
   - **`_TimeoutAsyncK8sApiClient.__init__`**: add `configuration=` parameter 
forwarded to `ApiClient`, matching the existing sync `_TimeoutK8sApiClient` 
pattern.
   - **`_load_config`**: initialise `self.client_configuration` to a fresh 
`async_client.Configuration()` when `None`, ensuring each hook instance owns an 
isolated object that `load_*` functions populate in-place (rather than calling 
`Configuration.set_default()`).
   - **`load_incluster_config`** call: pass 
`client_configuration=self.client_configuration`.
   - **`load_kube_config_from_dict`** call: pass 
`client_configuration=self.client_configuration`.
   - **`get_conn`**: pass `configuration=self.client_configuration` to 
`_TimeoutAsyncK8sApiClient`.
   
   The `kubeconfig_path`, `kube_config` (tempfile), and default-file branches 
already forwarded `client_configuration=self.client_configuration`; they now 
benefit from the initialisation fix so the value is never `None`.
   
   Seven new tests are added covering each changed path and a concurrency 
regression test using `asyncio.gather`.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Sonnet 4.6
   
   Generated-by: Claude Sonnet 4.6 following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
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]

Reply via email to