Skip to content

Commit 9478a65

Browse files
committed
promote apiGroup/apiVersion/resourceName to resourceBuilder
1 parent c8051a6 commit 9478a65

File tree

3 files changed

+27
-49
lines changed

3 files changed

+27
-49
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ abstract static class ResourceBuilder<
177177
final Class<ApiType> apiTypeClass;
178178
String namespace;
179179
String name;
180+
String apiGroup;
181+
String apiVersion;
182+
String resourceNamePlural;
180183

181184
ResourceBuilder(ApiClient client, Class<ApiType> apiTypeClass) {
182185
this.apiClient = client;
@@ -192,6 +195,21 @@ public T namespace(String namespace) {
192195
this.namespace = namespace;
193196
return (T) this;
194197
}
198+
199+
public T apiGroup(String apiGroup) {
200+
this.apiGroup = apiGroup;
201+
return (T) this;
202+
}
203+
204+
public T apiVersion(String apiVersion) {
205+
this.apiVersion = apiVersion;
206+
return (T) this;
207+
}
208+
209+
public T resourceNamePlural(String resourceNamePlural) {
210+
this.resourceNamePlural = resourceNamePlural;
211+
return (T) this;
212+
}
195213
}
196214

197215
abstract static class ResourceAndContainerBuilder<

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,18 @@ public class KubectlAnnotate<ApiType extends KubernetesObject>
2727
extends Kubectl.ResourceBuilder<ApiType, KubectlAnnotate<ApiType>>
2828
implements Kubectl.Executable<ApiType> {
2929

30-
private final ApiClient apiClient;
31-
private final Class<ApiType> apiTypeClass;
3230
private final Map<String, String> addingAnnotations;
3331

34-
private String apiGroup;
35-
private String apiVersion;
36-
private String resourceNamePlural;
37-
3832
KubectlAnnotate(ApiClient apiClient, Class<ApiType> apiTypeClass) {
3933
super(apiClient, apiTypeClass);
4034
this.addingAnnotations = new HashMap<>();
41-
this.apiTypeClass = apiTypeClass;
42-
this.apiClient = apiClient;
43-
}
44-
45-
public KubectlAnnotate<ApiType> apiGroup(String apiGroup) {
46-
this.apiGroup = apiGroup;
47-
return this;
48-
}
49-
50-
public KubectlAnnotate<ApiType> apiVersion(String apiVersion) {
51-
this.apiVersion = apiVersion;
52-
return this;
53-
}
54-
55-
public KubectlAnnotate<ApiType> resourceNamePlural(String resourceNamePlural) {
56-
this.resourceNamePlural = resourceNamePlural;
57-
return this;
5835
}
5936

6037
public KubectlAnnotate<ApiType> addAnnotation(String key, String value) {
6138
this.addingAnnotations.put(key, value);
6239
return this;
6340
}
6441

65-
private boolean isNamespaced() {
66-
return !StringUtils.isEmpty(namespace);
67-
}
68-
6942
@Override
7043
public ApiType execute() throws KubectlException {
7144
verifyArguments();
@@ -103,6 +76,10 @@ public ApiType execute() throws KubectlException {
10376
}
10477
}
10578

79+
public boolean isNamespaced() {
80+
return !StringUtils.isEmpty(namespace);
81+
}
82+
10683
private void verifyArguments() throws KubectlException {
10784
if (null == apiGroup) {
10885
throw new KubectlException("missing apiGroup argument");

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,19 @@
2626
public class KubectlLabel<ApiType extends KubernetesObject>
2727
extends Kubectl.ResourceBuilder<ApiType, KubectlLabel<ApiType>>
2828
implements Kubectl.Executable<ApiType> {
29+
2930
private final Map<String, String> addingLabels;
30-
private String apiGroup;
31-
private String apiVersion;
32-
private String resourceNamePlural;
3331

3432
KubectlLabel(ApiClient apiClient, Class<ApiType> apiTypeClass) {
3533
super(apiClient, apiTypeClass);
3634
this.addingLabels = new HashMap<>();
3735
}
3836

39-
public KubectlLabel<ApiType> apiGroup(String apiGroup) {
40-
this.apiGroup = apiGroup;
41-
return this;
42-
}
43-
44-
public KubectlLabel<ApiType> apiVersion(String apiVersion) {
45-
this.apiVersion = apiVersion;
46-
return this;
47-
}
48-
49-
public KubectlLabel<ApiType> resourceNamePlural(String resourceNamePlural) {
50-
this.resourceNamePlural = resourceNamePlural;
51-
return this;
52-
}
53-
5437
public KubectlLabel<ApiType> addLabel(String key, String value) {
5538
this.addingLabels.put(key, value);
5639
return this;
5740
}
5841

59-
private boolean isNamespaced() {
60-
return !StringUtils.isEmpty(namespace);
61-
}
62-
6342
@Override
6443
public ApiType execute() throws KubectlException {
6544
verifyArguments();
@@ -97,6 +76,10 @@ public ApiType execute() throws KubectlException {
9776
}
9877
}
9978

79+
public boolean isNamespaced() {
80+
return !StringUtils.isEmpty(namespace);
81+
}
82+
10083
private void verifyArguments() throws KubectlException {
10184
if (null == apiGroup) {
10285
throw new KubectlException("missing apiGroup argument");

0 commit comments

Comments
 (0)