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

fix: bump kubernetes- and openshift-client to 7.0.0 (#247) #248

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading