diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java index c8dc6bb5bc..e380f95738 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/internal/KubeConfigUtils.java @@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -181,10 +180,8 @@ public static int getNamedUserIndexFromConfig(Config config, String userName) { * @param kubeConfigPath path to KUBECONFIG * @throws IOException in case of failure while writing to file */ - public static void persistKubeConfigIntoFile(Config kubeConfig, String kubeConfigPath) throws IOException { - try (FileWriter writer = new FileWriter(kubeConfigPath)) { - writer.write(Serialization.asYaml(kubeConfig)); - } + public static void persistKubeConfigIntoFile(Config kubeConfig, File kubeConfigPath) throws IOException { + Files.writeString(kubeConfigPath.toPath(), Serialization.asYaml(kubeConfig)); } public static void merge(io.fabric8.kubernetes.client.Config clientConfig, Config kubeConfig, String context) { diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java index 1f76f38922..e45f01397d 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/OpenIDConnectionUtils.java @@ -215,7 +215,7 @@ public static OAuthToken persistOAuthToken(Config currentConfig, OAuthToken oAut if (Utils.isNotNullOrEmpty(token)) { namedAuthInfo.getUser().setToken(token); } - KubeConfigUtils.persistKubeConfigIntoFile(kubeConfig, currentConfig.getFile().getAbsolutePath()); + KubeConfigUtils.persistKubeConfigIntoFile(kubeConfig, currentConfig.getFile()); } catch (Exception ex) { LOGGER.warn("oidc: failure while persisting new tokens into KUBECONFIG", ex); }