Skip to content

Commit dfca9da

Browse files
authored
Merge pull request #1111 from yue9944882/kubectl-version
Kubectl version wrapper and shortcut
2 parents c663f27 + b2f0116 commit dfca9da

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/Kubectl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ public static <ApiType extends KubernetesObject> KubectlLabel<ApiType> label(
4848
return new KubectlLabel<>(apiClient, apiTypeClass);
4949
}
5050

51+
/**
52+
* Equivalence for `kubectl version`.
53+
*
54+
* @return the kubectl version
55+
*/
56+
public static KubectlVersion version() {
57+
return version(Configuration.getDefaultApiClient());
58+
}
59+
60+
/**
61+
* Equivalence for `kubectl version`.
62+
*
63+
* @param apiClient the api client instance
64+
* @return the kubectl version
65+
*/
66+
public static KubectlVersion version(ApiClient apiClient) {
67+
return new KubectlVersion(apiClient);
68+
}
69+
5170
/**
5271
* Executable executes a kubectl helper.
5372
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.extended.kubectl;
14+
15+
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
16+
import io.kubernetes.client.openapi.ApiClient;
17+
import io.kubernetes.client.openapi.ApiException;
18+
import io.kubernetes.client.openapi.models.VersionInfo;
19+
import io.kubernetes.client.util.version.Version;
20+
import java.io.IOException;
21+
22+
class KubectlVersion implements Kubectl.Executable<VersionInfo> {
23+
24+
private final Version version;
25+
26+
KubectlVersion(ApiClient apiClient) {
27+
this.version = new Version(apiClient);
28+
}
29+
30+
@Override
31+
public VersionInfo execute() throws KubectlException {
32+
try {
33+
return this.version.getVersion();
34+
} catch (ApiException | IOException e) {
35+
throw new KubectlException(e);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)