io.fabric8.kubernetes.client.VersionInfo Java Examples
The following examples show how to use
io.fabric8.kubernetes.client.VersionInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlatformFeaturesAvailabilityTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void versionInfoFromMap(VertxTestContext context) throws ParseException { String version = "major=1\n" + "minor=16\n" + "gitVersion=v1.16.2\n" + "gitCommit=c97fe5036ef3df2967d086711e6c0c405941e14b\n" + "gitTreeState=clean\n" + "buildDate=2019-10-15T19:09:08Z\n" + "goVersion=go1.12.10\n" + "compiler=gc\n" + "platform=linux/amd64"; VersionInfo vi = new VersionInfo(Util.parseMap(version)); context.verify(() -> { assertThat(vi.getMajor(), is("1")); assertThat(vi.getMinor(), is("16")); }); context.completeNow(); }
Example #2
Source File: OpenShiftVersionExample.java From kubernetes-client with Apache License 2.0 | 6 votes |
public static void main(String args[]) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); try(final OpenShiftClient client = new DefaultOpenShiftClient(config)) { VersionInfo versionInfo = client.getVersion(); log("Version details of this OpenShift cluster :-"); log("Major : ", versionInfo.getMajor()); log("Minor : ", versionInfo.getMinor()); log("GitVersion : ", versionInfo.getGitVersion()); log("BuildDate : ", versionInfo.getBuildDate()); log("GitTreeState : ", versionInfo.getGitTreeState()); log("Platform : ", versionInfo.getPlatform()); log("GitVersion : ", versionInfo.getGitVersion()); log("GoVersion : ", versionInfo.getGoVersion()); log("GitCommit : ", versionInfo.getGitCommit()); } }
Example #3
Source File: ClusterOperationsImpl.java From kubernetes-client with Apache License 2.0 | 6 votes |
public VersionInfo fetchVersion() { try { Response response = handleVersionGet(versionEndpoint); // Handle Openshift 4 version case if (HttpURLConnection.HTTP_NOT_FOUND == response.code() && versionEndpoint.equals(OPENSHIFT_VERSION_ENDPOINT)) { response.close(); return fetchOpenshift4Version(); } Map<String, String> myMap = objectMapper.readValue(response.body().string(), HashMap.class); return fetchVersionInfoFromResponse(myMap); } catch(Exception e) { KubernetesClientException.launderThrowable(e); } return null; }
Example #4
Source File: KubernetesExtension.java From dekorate with Apache License 2.0 | 5 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { try { VersionInfo version = getKubernetesClient(context).getVersion(); String message = "Found version:" + version.getMajor() + "." + version.getMinor(); LOGGER.info(message); return ConditionEvaluationResult.enabled(message); } catch (Throwable t) { String reason = "Could not communicate with KubernetesExtension API server."; LOGGER.error(reason); return ConditionEvaluationResult.disabled(reason); } }
Example #5
Source File: PlatformFeaturesAvailability.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
public static Future<PlatformFeaturesAvailability> create(Vertx vertx, KubernetesClient client) { Promise<PlatformFeaturesAvailability> pfaPromise = Promise.promise(); OkHttpClient httpClient = getOkHttpClient(client); PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(); Future<VersionInfo> futureVersion = getVersionInfo(vertx, client); futureVersion.compose(versionInfo -> { String major = versionInfo.getMajor().equals("") ? Integer.toString(KubernetesVersion.MINIMAL_SUPPORTED_MAJOR) : versionInfo.getMajor(); String minor = versionInfo.getMinor().equals("") ? Integer.toString(KubernetesVersion.MINIMAL_SUPPORTED_MINOR) : versionInfo.getMinor(); pfa.setKubernetesVersion(new KubernetesVersion(Integer.parseInt(major.split("\\D")[0]), Integer.parseInt(minor.split("\\D")[0]))); return checkApiAvailability(vertx, httpClient, client.getMasterUrl().toString(), "route.openshift.io", "v1"); }).compose(supported -> { pfa.setRoutes(supported); return checkApiAvailability(vertx, httpClient, client.getMasterUrl().toString(), "build.openshift.io", "v1"); }).compose(supported -> { pfa.setBuilds(supported); return checkApiAvailability(vertx, httpClient, client.getMasterUrl().toString(), "apps.openshift.io", "v1"); }).compose(supported -> { pfa.setApps(supported); return checkApiAvailability(vertx, httpClient, client.getMasterUrl().toString(), "image.openshift.io", "v1"); }).compose(supported -> { pfa.setImages(supported); return Future.succeededFuture(pfa); }) .onComplete(pfaPromise); return pfaPromise.future(); }
Example #6
Source File: PlatformFeaturesAvailability.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
private static Future<VersionInfo> getVersionInfoFromKubernetes(Vertx vertx, KubernetesClient client) { Promise<VersionInfo> promise = Promise.promise(); vertx.executeBlocking(request -> { try { request.complete(client.getVersion()); } catch (Exception e) { log.error("Detection of Kubernetes version failed.", e); request.fail(e); } }, promise); return promise.future(); }
Example #7
Source File: ClusterOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
private VersionInfo fetchVersionInfoFromResponse(Map<String, String> responseAsMap) throws ParseException { return new VersionInfo.Builder().withBuildDate(responseAsMap.get(VersionInfo.VERSION_KEYS.BUILD_DATE)) .withGitCommit(responseAsMap.get(VersionInfo.VERSION_KEYS.GIT_COMMIT)) .withGitVersion(responseAsMap.get(VersionInfo.VERSION_KEYS.GIT_VERSION)) .withMajor(responseAsMap.get(VersionInfo.VERSION_KEYS.MAJOR)) .withMinor(responseAsMap.get(VersionInfo.VERSION_KEYS.MINOR)) .withGitTreeState(responseAsMap.get(VersionInfo.VERSION_KEYS.GIT_TREE_STATE)) .withPlatform(responseAsMap.get(VersionInfo.VERSION_KEYS.PLATFORM)) .withGoVersion(responseAsMap.get(VersionInfo.VERSION_KEYS.GO_VERSION)) .withCompiler(responseAsMap.get(VersionInfo.VERSION_KEYS.COMPILER)) .build(); }
Example #8
Source File: ClusterOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
private VersionInfo fetchOpenshift4Version() throws IOException, ParseException { Response response = handleVersionGet(OPENSHIFT4_VERSION_ENDPOINT); if (response.isSuccessful() && response.body() != null) { ClusterVersionList clusterVersionList = objectMapper.readValue(response.body().string(), ClusterVersionList.class); if (!clusterVersionList.getItems().isEmpty()) { return VersionInfo.parseVersionInfoFromClusterVersion(clusterVersionList.getItems().get(0)); } } return null; }
Example #9
Source File: Kubernetes.java From enmasse with Apache License 2.0 | 4 votes |
public double getKubernetesVersion() { try (var client = new DefaultKubernetesClient()) { final VersionInfo versionInfo = client.getVersion(); return Double.parseDouble(versionInfo.getMajor() + "." + versionInfo.getMinor().replace("+", "")); } }
Example #10
Source File: ManagedOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public VersionInfo getVersion() { return delegate.getVersion(); }
Example #11
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public VersionInfo getVersion() { return delegate.getVersion(); }
Example #12
Source File: VersionInfoTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void testClusterVersioningOpenshift4() throws ParseException { openshiftServer.expect().get().withPath("/openshift/version").andReturn(404, "").always(); openshiftServer.expect().get().withPath("/apis/config.openshift.io/v1/clusterversions").andReturn(200, "{" + " \"apiVersion\": \"config.openshift.io/v1\"," + " \"items\": [" + " {" + " \"apiVersion\": \"config.openshift.io/v1\"," + " \"kind\": \"ClusterVersion\"," + " \"metadata\": {" + " \"creationTimestamp\": \"2020-01-30T04:05:33Z\"," + " \"generation\": 2," + " \"name\": \"version\"," + " \"resourceVersion\": \"44758\"," + " \"selfLink\": \"/apis/config.openshift.io/v1/clusterversions/version\"," + " \"uid\": \"c301755d-4315-11ea-9872-52540022f9dd\"" + " }," + " \"spec\": {" + " \"channel\": \"stable-4.2\"," + " \"clusterID\": \"c92835a5-395d-4448-840d-6a223f9a02c7\"," + " \"upstream\": \"https://api.openshift.com/api/upgrades_info/v1/graph\"" + " }," + " \"status\": {" + " \"availableUpdates\": [" + " {" + " \"force\": false," + " \"image\": \"quay.io/openshift-release-dev/ocp-release@sha256:e5a6e348721c38a78d9299284fbb5c60fb340135a86b674b038500bf190ad514\"," + " \"version\": \"4.2.16\"" + " }" + " ]," + " \"conditions\": [" + " {" + " \"lastTransitionTime\": \"2020-01-30T04:05:35Z\"," + " \"status\": \"False\"," + " \"type\": \"Available\"" + " }," + " {" + " \"lastTransitionTime\": \"2020-01-30T04:31:38Z\"," + " \"message\": \"Cluster operator monitoring is still updating\"," + " \"reason\": \"ClusterOperatorNotAvailable\"," + " \"status\": \"True\"," + " \"type\": \"Failing\"" + " }," + " {" + " \"lastTransitionTime\": \"2020-01-30T04:05:35Z\"," + " \"message\": \"Unable to apply 4.2.14: the cluster operator monitoring has not yet successfully rolled out\"," + " \"reason\": \"ClusterOperatorNotAvailable\"," + " \"status\": \"True\"," + " \"type\": \"Progressing\"" + " }," + " {" + " \"lastTransitionTime\": \"2020-01-30T04:05:36Z\"," + " \"status\": \"True\"," + " \"type\": \"RetrievedUpdates\"" + " }" + " ]," + " \"desired\": {" + " \"force\": false," + " \"image\": \"quay.io/openshift-release-dev/ocp-release@sha256:3fabe939da31f9a31f509251b9f73d321e367aba2d09ff392c2f452f6433a95a\"," + " \"version\": \"4.2.14\"" + " }," + " \"history\": [" + " {" + " \"completionTime\": null," + " \"image\": \"quay.io/openshift-release-dev/ocp-release@sha256:3fabe939da31f9a31f509251b9f73d321e367aba2d09ff392c2f452f6433a95a\"," + " \"startedTime\": \"2020-01-30T04:05:35Z\"," + " \"state\": \"Partial\"," + " \"verified\": false," + " \"version\": \"4.2.14\"" + " }" + " ]," + " \"observedGeneration\": 1," + " \"versionHash\": \"kEuk9MZ8sK4=\"" + " }" + " }" + " ]," + " \"kind\": \"ClusterVersionList\"," + " \"metadata\": {" + " \"continue\": \"\"," + " \"resourceVersion\": \"62446\"," + " \"selfLink\": \"/apis/config.openshift.io/v1/clusterversions\"" + " }" + "}").once(); OpenShiftClient openShiftClient = openshiftServer.getOpenshiftClient(); VersionInfo versionInfo = openShiftClient.getVersion(); assertEquals("4", versionInfo.getMajor()); assertEquals("2.14", versionInfo.getMinor()); }
Example #13
Source File: KubernetesDeploy.java From quarkus with Apache License 2.0 | 4 votes |
private Result doCheck() { Config config = ConfigProvider.getConfig(); if (!config.getOptionalValue(DEPLOY, Boolean.class).orElse(false)) { return Result.notConfigured(); } // No need to perform the check multiple times. if (serverFound) { return Result.enabled(); } KubernetesClient client = KubernetesClientUtils.createClient(); String masterURL = client.getConfiguration().getMasterUrl(); try { //Let's check if we can connect. VersionInfo version = client.getVersion(); if (version == null) { return Result.exceptional(new RuntimeException( "Although a Kubernetes deployment was requested, it however cannot take place because the version of the API Server at '" + masterURL + "' could not be determined. Please ensure that a valid token is being used.")); } log.info("Kubernetes API Server at '" + masterURL + "' successfully contacted."); log.debugf("Kubernetes Version: %s.%s", version.getMajor(), version.getMinor()); serverFound = true; return Result.enabled(); } catch (Exception e) { if (e.getCause() instanceof SSLHandshakeException) { return Result.exceptional(new RuntimeException( "Although a Kubernetes deployment was requested, it however cannot take place because the API Server (at '" + masterURL + "') certificates are not trusted. The certificates can be configured using the relevant configuration propertiers under the 'quarkus.kubernetes-client' config root, or \"quarkus.kubernetes-client.trust-certs=true\" can be set to explicitly trust the certificates (not recommended)", e)); } else { return Result.exceptional(new RuntimeException( "Although a Kubernetes deployment was requested, it however cannot take place because there was an error during communication with the API Server at '" + masterURL + "'", e)); } } finally { client.close(); } }
Example #14
Source File: KubeClient.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * Method which return kubernetes version * @return kubernetes version */ public String clusterKubernetesVersion() { // This is basically workaround cause this.client.getVersion() returns null every time VersionInfo versionInfo = new DefaultKubernetesClient().getVersion(); return versionInfo.getMajor() + "." + versionInfo.getMinor().replace("+", ""); }
Example #15
Source File: AbstractCrdIT.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
protected void assumeKube1_11Plus() { VersionInfo version = new DefaultKubernetesClient().getVersion(); assumeTrue("1".equals(version.getMajor()) && Integer.parseInt(version.getMinor().split("\\D")[0]) >= 11); }
Example #16
Source File: PlatformFeaturesAvailability.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * Gets the Kubernetes VersionInfo. It either used from the /version endpoint or from the STRIMZI_KUBERNETES_VERSION * environment variable. If defined, the environment variable will take the precedence. Otherwise the API server * endpoint will be used. * * And example of the STRIMZI_KUBERNETES_VERSION environment variable in Cluster Operator deployment: * <pre><code> * env: * - name: STRIMZI_KUBERNETES_VERSION * value: | * major=1 * minor=16 * gitVersion=v1.16.2 * gitCommit=c97fe5036ef3df2967d086711e6c0c405941e14b * gitTreeState=clean * buildDate=2019-10-15T19:09:08Z * goVersion=go1.12.10 * compiler=gc * platform=linux/amd64 * </code></pre> * * @param vertx Instance of Vert.x * @param client Fabric8 Kubernetes client * @return Future with the VersionInfo object describing the Kubernetes version */ private static Future<VersionInfo> getVersionInfo(Vertx vertx, KubernetesClient client) { Future<VersionInfo> futureVersion; String kubernetesVersion = System.getenv("STRIMZI_KUBERNETES_VERSION"); if (kubernetesVersion != null) { try { futureVersion = Future.succeededFuture(new VersionInfo(Util.parseMap(kubernetesVersion))); } catch (ParseException e) { throw new RuntimeException("Failed to parse the Kubernetes version information provided through STRIMZI_KUBERNETES_VERSION environment variable", e); } } else { futureVersion = getVersionInfoFromKubernetes(vertx, client); } return futureVersion; }
Example #17
Source File: OpenShiftClient.java From kubernetes-client with Apache License 2.0 | votes |
VersionInfo getVersion();