Skip to content

Commit 77b78c8

Browse files
lilyz-aiclaude
andcommitted
fix: avoid global Configuration singleton race in read_config_map
Each call to read_config_map was mutating the kubernetes_asyncio global Configuration._default via load_incluster_config(). Concurrent async requests could race each other, leaving the global transiently empty so that CoreV1Api() would construct an ApiClient with no host/token → 401. Fix by passing an explicit client_configuration object to load_incluster_config/load_kube_config and binding ApiClient to it directly, so no shared global state is touched. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3a18aee commit 77b78c8

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

model-engine/model_engine_server/core/configmap.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717
async def read_config_map(
1818
config_map_name: str, namespace: str = hmi_config.gateway_namespace
1919
) -> Dict[str, str]:
20+
configuration = client.Configuration()
2021
try:
21-
kube_config.load_incluster_config()
22+
kube_config.load_incluster_config(client_configuration=configuration)
2223
except ConfigException:
2324
logger.info("No incluster kubernetes config, falling back to local")
24-
await kube_config.load_kube_config()
25-
26-
core_api = client.CoreV1Api()
27-
28-
try:
29-
config_map = await core_api.read_namespaced_config_map(
30-
name=config_map_name, namespace=namespace
31-
)
32-
return config_map.data
33-
except ApiException as e:
34-
logger.exception(f"Error reading configmap {config_map_name}")
35-
raise e
25+
await kube_config.load_kube_config(client_configuration=configuration)
26+
27+
async with client.ApiClient(configuration) as api_client:
28+
core_api = client.CoreV1Api(api_client)
29+
30+
try:
31+
config_map = await core_api.read_namespaced_config_map(
32+
name=config_map_name, namespace=namespace
33+
)
34+
return config_map.data
35+
except ApiException as e:
36+
logger.exception(f"Error reading configmap {config_map_name}")
37+
raise e

0 commit comments

Comments
 (0)