Skip to content

Commit f3a7126

Browse files
authored
Merge pull request #1136 from yue9944882/refactor/apitypeclass-lowerbound
Refactor(kubectl): get rid of force api type class casting
2 parents 6b43ab6 + c715dd4 commit f3a7126

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public static KubectlExec exec(ApiClient apiClient) {
105105
/**
106106
* Equivalent for `kubectl exec`
107107
*
108-
* @param apiClient The api client instance
109108
* @return the kubectl exec operator
110109
*/
111110
public static KubectlExec exec() {
@@ -128,13 +127,14 @@ public static interface Executable<OUTPUT> {
128127
OUTPUT execute() throws KubectlException;
129128
}
130129

131-
abstract static class ResourceBuilder<T extends ResourceBuilder<T>> {
130+
abstract static class ResourceBuilder<
131+
ApiType extends KubernetesObject, T extends ResourceBuilder<ApiType, T>> {
132132
final ApiClient apiClient;
133-
final Class<?> apiTypeClass;
133+
final Class<ApiType> apiTypeClass;
134134
String namespace;
135135
String name;
136136

137-
ResourceBuilder(ApiClient client, Class<?> apiTypeClass) {
137+
ResourceBuilder(ApiClient client, Class<ApiType> apiTypeClass) {
138138
this.apiClient = client;
139139
this.apiTypeClass = apiTypeClass;
140140
}
@@ -150,11 +150,12 @@ public T namespace(String namespace) {
150150
}
151151
}
152152

153-
abstract static class ResourceAndContainerBuilder<T extends ResourceAndContainerBuilder<T>>
154-
extends ResourceBuilder<T> {
153+
abstract static class ResourceAndContainerBuilder<
154+
ApiType extends KubernetesObject, T extends ResourceAndContainerBuilder<ApiType, T>>
155+
extends ResourceBuilder<ApiType, T> {
155156
String container;
156157

157-
ResourceAndContainerBuilder(ApiClient client, Class<?> apiTypeClass) {
158+
ResourceAndContainerBuilder(ApiClient client, Class<ApiType> apiTypeClass) {
158159
super(client, apiTypeClass);
159160
}
160161

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.InputStream;
2424
import java.io.OutputStream;
2525

26-
public class KubectlExec extends Kubectl.ResourceAndContainerBuilder<KubectlExec>
26+
public class KubectlExec extends Kubectl.ResourceAndContainerBuilder<V1Pod, KubectlExec>
2727
implements Kubectl.Executable<V1Pod> {
2828
private String[] command;
2929
private boolean stdin;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import org.apache.commons.lang.StringUtils;
2525

2626
public class KubectlLabel<ApiType extends KubernetesObject>
27-
extends Kubectl.ResourceBuilder<KubectlLabel<ApiType>> implements Kubectl.Executable<ApiType> {
27+
extends Kubectl.ResourceBuilder<ApiType, KubectlLabel<ApiType>>
28+
implements Kubectl.Executable<ApiType> {
2829
private final Map<String, String> addingLabels;
2930
private String apiGroup;
3031
private String apiVersion;
@@ -64,7 +65,7 @@ public ApiType execute() throws KubectlException {
6465
verifyArguments();
6566
GenericKubernetesApi<ApiType, KubernetesListObject> api =
6667
new GenericKubernetesApi<>(
67-
(Class<ApiType>) apiTypeClass,
68+
apiTypeClass,
6869
KubernetesListObject.class,
6970
apiGroup,
7071
apiVersion,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
import io.kubernetes.client.util.PatchUtils;
2424

2525
public class KubectlScale<ApiType extends KubernetesObject>
26-
extends Kubectl.ResourceBuilder<KubectlScale<ApiType>> implements Kubectl.Executable<ApiType> {
26+
extends Kubectl.ResourceBuilder<ApiType, KubectlScale<ApiType>>
27+
implements Kubectl.Executable<ApiType> {
2728
private final AppsV1Api api;
2829
private int replicas;
2930

0 commit comments

Comments
 (0)