File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed
Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ async def reauthenticate(self) -> None:
7878 else :
7979 if self ._kubeconfig_path_or_dict is not False :
8080 await self ._load_kubeconfig ()
81- if self ._serviceaccount and not self . server :
81+ if self ._serviceaccount :
8282 await self ._load_service_account ()
8383 if not self .server :
8484 raise ValueError ("Unable to find valid credentials" )
@@ -264,10 +264,11 @@ async def _load_service_account(self) -> None:
264264 self ._serviceaccount = os .path .expanduser (self ._serviceaccount )
265265 if not os .path .isdir (self ._serviceaccount ):
266266 return
267- self .server = self ._format_server_address (
268- os .environ ["KUBERNETES_SERVICE_HOST" ],
269- os .environ ["KUBERNETES_SERVICE_PORT" ],
270- )
267+ if not self .server :
268+ self .server = self ._format_server_address (
269+ os .environ ["KUBERNETES_SERVICE_HOST" ],
270+ os .environ ["KUBERNETES_SERVICE_PORT" ],
271+ )
271272 async with await anyio .open_file (
272273 os .path .join (self ._serviceaccount , "token" )
273274 ) as f :
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ def test_kubeconfig_isdir_fail(tmp_path):
243243 kr8s .api (kubeconfig = tmp_path )
244244
245245
246- async def test_service_account (serviceaccount ):
246+ async def test_service_account (serviceaccount , k8s_token ):
247247 api = await kr8s .asyncio .api (
248248 serviceaccount = serviceaccount , kubeconfig = "/no/file/here"
249249 )
@@ -252,10 +252,18 @@ async def test_service_account(serviceaccount):
252252 serviceaccount = Path (serviceaccount )
253253 assert api .auth .server
254254 assert api .auth .token == (serviceaccount / "token" ).read_text ()
255- assert str (serviceaccount ) in api .auth .server_ca_file
255+ assert api .auth .token == k8s_token
256+ assert api .auth .server_ca_file
257+ assert str (serviceaccount ) in str (api .auth .server_ca_file )
256258 assert "BEGIN CERTIFICATE" in Path (api .auth .server_ca_file ).read_text ()
257259 assert api .auth .namespace == (serviceaccount / "namespace" ).read_text ()
258260
261+ (serviceaccount / "token" ).write_text ("foo" )
262+ await api .reauthenticate ()
263+ assert api .auth .token == "foo"
264+
265+ (serviceaccount / "token" ).write_text (k8s_token )
266+
259267
260268async def test_service_account_with_kubeconfig_namespace (serviceaccount ):
261269 kubeconfig = await KubeConfig (
You can’t perform that action at this time.
0 commit comments