16
16
package io .fabric8 .kubernetes .client .utils ;
17
17
18
18
import io .fabric8 .kubernetes .api .model .AuthInfo ;
19
+ import io .fabric8 .kubernetes .api .model .AuthProviderConfig ;
19
20
import io .fabric8 .kubernetes .api .model .NamedAuthInfo ;
20
21
import io .fabric8 .kubernetes .api .model .NamedContext ;
21
22
import io .fabric8 .kubernetes .client .Config ;
37
38
import java .security .cert .CertificateException ;
38
39
import java .security .spec .InvalidKeySpecException ;
39
40
import java .time .Instant ;
40
- import java .util .Base64 ;
41
- import java .util .Collections ;
42
- import java .util .LinkedHashMap ;
43
- import java .util .Map ;
41
+ import java .util .*;
44
42
import java .util .concurrent .CompletableFuture ;
45
43
import java .util .function .Consumer ;
46
44
@@ -242,6 +240,12 @@ static boolean persistKubeConfigWithUpdatedToken(Config currentConfig, Map<Strin
242
240
*/
243
241
public static boolean persistKubeConfigWithUpdatedAuthInfo (Config currentConfig , Consumer <AuthInfo > updateAction )
244
242
throws IOException {
243
+ AuthInfo authInfo = new AuthInfo ();
244
+ authInfo .setAuthProvider (new AuthProviderConfig (new HashMap <>(2 ), currentConfig .getAuthProvider ().getName ()));
245
+ updateAction .accept (authInfo );
246
+ //update new auth info to in-memory config
247
+ currentConfig .getAuthProvider ().getConfig ().putAll (authInfo .getAuthProvider ().getConfig ());
248
+
245
249
if (currentConfig .getFile () == null ) {
246
250
return false ;
247
251
}
@@ -259,10 +263,13 @@ public static boolean persistKubeConfigWithUpdatedAuthInfo(Config currentConfig,
259
263
config .getUsers ().add (result );
260
264
return result ;
261
265
});
266
+ //update new auth info to kubeConfig
262
267
if (namedAuthInfo .getUser () == null ) {
263
- namedAuthInfo .setUser (new AuthInfo ());
268
+ namedAuthInfo .setUser (authInfo );
269
+ } else {
270
+ Optional .ofNullable (authInfo .getToken ()).ifPresent (t -> namedAuthInfo .getUser ().setToken (t ));
271
+ namedAuthInfo .getUser ().getAuthProvider ().getConfig ().putAll (authInfo .getAuthProvider ().getConfig ());
264
272
}
265
- updateAction .accept (namedAuthInfo .getUser ());
266
273
// Persist changes to KUBECONFIG
267
274
KubeConfigUtils .persistKubeConfigIntoFile (config , currentConfig .getFile ().getAbsolutePath ());
268
275
return true ;
0 commit comments