Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(config): persistKubeConfigIntoFile uses File instead of String #6546

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading