Skip to content

Commit 8180143

Browse files
committed
kubectl patch fix
1 parent 351ffa1 commit 8180143

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

docs/kubectl-equivalence-in-java.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#Kubectl Equivalence in Java
2+
3+
__TL;DR__: Get used to kubectl? Now the kubernetes Java client library has releases a set of
4+
helpful client utilities which has the similar input argument interface as the kubectl binary
5+
does. Especially the developers who're already familiar with kubectl commands, after reading
6+
this document, you will know how to program to operate kubernetes as neat as kubectl.
7+
8+
9+
### Kubectl vs Direct HTTP client
10+
11+
12+
### Difference between kubectl commands and direct
13+
14+
15+
### Manifest of Supported Commands
16+
17+
18+
#### Kubectl get

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
*/
1313
package io.kubernetes.client.extended.kubectl;
1414

15-
import io.kubernetes.client.common.KubernetesListObject;
1615
import io.kubernetes.client.common.KubernetesObject;
1716
import io.kubernetes.client.custom.V1Patch;
17+
import io.kubernetes.client.util.ModelMapper;
1818
import io.kubernetes.client.util.generic.GenericKubernetesApi;
1919

2020
public class KubectlPatch<ApiType extends KubernetesObject>
2121
extends Kubectl.ResourceBuilder<ApiType, KubectlPatch<ApiType>>
2222
implements Kubectl.Executable<ApiType> {
2323

24-
private Class<ApiType> apiTypeClass;
25-
private Class<KubernetesListObject> apiListTypeClass;
24+
private String patchType;
2625
private V1Patch patchContent;
2726

2827
KubectlPatch(Class<ApiType> apiTypeClass) {
@@ -34,9 +33,18 @@ public KubectlPatch patchContent(V1Patch patchContent) {
3433
return this;
3534
}
3635

36+
public KubectlPatch patchType(String patchType) {
37+
this.patchType = patchType;
38+
return this;
39+
}
40+
3741
@Override
3842
public ApiType execute() {
3943
GenericKubernetesApi genericKubernetesApi = getGenericApi();
40-
return (ApiType) genericKubernetesApi.patch(namespace, name, patchContent);
44+
if (ModelMapper.isNamespaced(apiTypeClass)) {
45+
return (ApiType) genericKubernetesApi.patch(namespace, name, patchType, patchContent);
46+
} else {
47+
return (ApiType) genericKubernetesApi.patch(name, patchType, patchContent);
48+
}
4149
}
4250
}

0 commit comments

Comments
 (0)