Skip to content

Commit

Permalink
bump kubernetes-client to 7.0.0 (#247)
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish committed Dec 11, 2024
1 parent 9f738b1 commit 728cdbb
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 981 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ nexusUser=invalid
nexusPassword=invalid

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
ideaVersion=2024.2
ideaVersion=2024.3

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion=8.5
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
# libraries
junit = "4.13.2"
kubernetes-client = "6.12.0"
kubernetes-client = "7.0.0"
jackson-core = "2.17.0"
commons-lang3 = "3.12.0"
commons-exec = "1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,32 @@
import io.fabric8.kubernetes.client.VersionInfo;
import io.fabric8.openshift.client.OpenShiftClient;

import java.net.HttpURLConnection;

public class ClusterHelper {

private ClusterHelper() {
//avoid instanciation
}

public static boolean isOpenShift(KubernetesClient client) {
return client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false);
try {
return client.hasApiGroup(OpenShiftClient.BASE_API_GROUP, false);
} catch (KubernetesClientException e) {
return false;
}
}

public static ClusterInfo getClusterInfo(KubernetesClient client) {
if (client instanceof OpenShiftClient) {
return new ClusterInfo(
getKubernetesVersion((OpenShiftClient) client),
true,
getOpenShiftVersion((OpenShiftClient) client));

} else if (client.adapt(OpenShiftClient.class) != null && client.adapt(OpenShiftClient.class).isSupported()){
OpenShiftClient openShiftClient = getOpenShiftClient(client);
if (openShiftClient != null) {
return new ClusterInfo(
getKubernetesVersion(client),
true,
getOpenShiftVersion(client));
getOpenShiftVersion(openShiftClient));
} else {
return new ClusterInfo(
getKubernetesVersion(client),
false,
"");

}
}

private static String getKubernetesVersion(OpenShiftClient client) {
try {
KubernetesClient kclient = new KubernetesClientBuilder().withConfig(client.getConfiguration()).build();
return getKubernetesVersion(kclient);
} catch (KubernetesClientException e) {
return null;
}
}

Expand All @@ -63,18 +50,23 @@ private static String getKubernetesVersion(KubernetesClient client) {
return version != null ? version.getGitVersion() : "";
}

private static String getOpenShiftVersion(KubernetesClient client) {
try {
OpenShiftClient oclient = client.adapt(OpenShiftClient.class);
return getOpenShiftVersion(oclient);
} catch (KubernetesClientException e) {
private static OpenShiftClient getOpenShiftClient(KubernetesClient client) {
if (client instanceof OpenShiftClient) {
return (OpenShiftClient) client;
} else if (isOpenShift(client)) {
return client.adapt(OpenShiftClient.class);
} else {
return null;
}
}

private static String getOpenShiftVersion(OpenShiftClient client) {
VersionInfo version = client.getVersion();
return version != null && version.getMajor() != null ? getVersion(version.getMajor(), version.getMinor()) : "";
if (version != null && version.getMajor() != null) {
return getVersion(version.getMajor(), version.getMinor());
} else {
return "";
}
}

private static String getVersion(String major, String minor) {
Expand Down
Loading

0 comments on commit 728cdbb

Please sign in to comment.