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): refresh relies in non-deprecated method fromKubeconfig #6548

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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 @@ -823,19 +823,22 @@ public static Config fromKubeconfig(String context, String kubeconfigContents, S
* @return this Config instance with the refreshed values (if applicable)
*/
public Config refresh() {
final String currentContextName = this.getCurrentContext() != null ? this.getCurrentContext().getName() : null;
if (Utils.isNotNullOrEmpty(this.oauthToken)) {
final String currentContextName = getCurrentContext() != null ? getCurrentContext().getName() : null;
if (Utils.isNotNullOrEmpty(oauthToken)) {
return this;
}
if (this.autoConfigure) {
if (autoConfigure) {
return Config.autoConfigure(currentContextName);
}
if (this.file != null) {
String kubeconfigContents = getKubeconfigContents(this.file);
if (kubeconfigContents == null) {
return this; // getKubeconfigContents will have logged an exception
if (file != null) {
if (loadKubeConfigContents(file) == null) {
return this; // loadKubeConfigContents will have logged an exception
}
final var refreshedConfig = Config.fromKubeconfig(currentContextName, file);
if (!disableAutoConfig()) {
postAutoConfigure(refreshedConfig);
}
return Config.fromKubeconfig(currentContextName, kubeconfigContents, this.file.getPath());
return refreshedConfig;
}
// nothing to refresh - the kubeconfig was directly supplied
return this;
Expand All @@ -852,7 +855,7 @@ private static File findKubeConfigFile() {
return null;
}
LOGGER.debug("Found for Kubernetes config at: [{}].", kubeConfigFile.getPath());
if (Utils.isNullOrEmpty(getKubeconfigContents(kubeConfigFile))) {
if (Utils.isNullOrEmpty(loadKubeConfigContents(kubeConfigFile))) {
return null;
}
return kubeConfigFile;
Expand All @@ -875,15 +878,13 @@ public static String getKubeconfigFilename() {
return fileName;
}

private static String getKubeconfigContents(File kubeConfigFile) {
String kubeconfigContents = null;
private static String loadKubeConfigContents(File kubeConfigFile) {
try (FileReader reader = new FileReader(kubeConfigFile)) {
kubeconfigContents = IOHelpers.readFully(reader);
return IOHelpers.readFully(reader);
} catch (IOException e) {
LOGGER.error("Could not load Kubernetes config file from {}", kubeConfigFile.getPath(), e);
return null;
}
return kubeconfigContents;
}

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Loading