File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ from app .compat import ensure_urllib3_getheaders
2+
3+ # Ensure urllib3 2.x exposes HTTPResponse.getheaders for kubernetes client compatibility.
4+ ensure_urllib3_getheaders ()
Original file line number Diff line number Diff line change 1+ """
2+ Compatibility shims for third-party libraries.
3+
4+ Currently used to keep kubernetes-python working with urllib3 2.x, which
5+ removed HTTPResponse.getheaders(). Older kubernetes versions still call
6+ getheaders when building ApiException objects. This shim reintroduces a
7+ minimal getheaders that mirrors the previous behavior.
8+ """
9+ from urllib3 .response import HTTPResponse
10+
11+
12+ def ensure_urllib3_getheaders () -> None :
13+ """Add HTTPResponse.getheaders if urllib3 2.x removed it.
14+
15+ Returns the header items as a list of (key, value) tuples, matching the
16+ old http.client.HTTPResponse API used by kubernetes-python.
17+ """
18+ if not hasattr (HTTPResponse , "getheaders" ):
19+ def _getheaders (self ): # type: ignore[override]
20+ return list (self .headers .items ())
21+
22+ HTTPResponse .getheaders = _getheaders # type: ignore[attr-defined]
Original file line number Diff line number Diff line change 11from fastapi import FastAPI
22from fastapi .middleware .cors import CORSMiddleware
3+
4+ from app .compat import ensure_urllib3_getheaders
5+
6+ # Restore HTTPResponse.getheaders expected by kubernetes-python when running with urllib3 2.x.
7+ ensure_urllib3_getheaders ()
8+
39from kubernetes import config
410
511# Load the kubeconfig file
You can’t perform that action at this time.
0 commit comments