Skip to content

Commit e253ce8

Browse files
authored
Merge pull request #1285 from yue9944882/bugfix/kubectl-replace-verify
Bugfix(kubectl): Name argument is not required for kubectl replace
2 parents 154d739 + dc26736 commit e253ce8

File tree

5 files changed

+79
-78
lines changed

5 files changed

+79
-78
lines changed

e2e/src/test/groovy/io/kubernetes/client/e2e/kubectl/KubectlApplyTest.groovy

Lines changed: 0 additions & 29 deletions
This file was deleted.

e2e/src/test/groovy/io/kubernetes/client/e2e/kubectl/KubectlCreateTest.groovy

Lines changed: 0 additions & 27 deletions
This file was deleted.

e2e/src/test/groovy/io/kubernetes/client/e2e/kubectl/KubectlLabelTest.groovy

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package io.kubernetes.client.e2e.kubectl
2+
3+
import io.kubernetes.client.extended.kubectl.Kubectl
4+
import io.kubernetes.client.extended.kubectl.exception.KubectlException
5+
import io.kubernetes.client.openapi.ApiException
6+
import io.kubernetes.client.openapi.models.V1Namespace
7+
import io.kubernetes.client.openapi.models.V1ObjectMeta
8+
import io.kubernetes.client.util.ClientBuilder
9+
import spock.lang.Specification
10+
import spock.util.concurrent.PollingConditions
11+
12+
class KubectlNamespaceTest extends Specification {
13+
14+
def "Kubectl manipulating namespace should work"() {
15+
given:
16+
def apiClient = ClientBuilder.defaultClient();
17+
18+
when:
19+
def createdNamespace = Kubectl.create(V1Namespace.class)
20+
.apiClient(apiClient)
21+
.resource(new V1Namespace()
22+
.apiVersion("v1")
23+
.metadata(
24+
new V1ObjectMeta()
25+
.name("foo")))
26+
.execute()
27+
then:
28+
createdNamespace != null
29+
Kubectl.get(V1Namespace.class)
30+
.apiClient(apiClient)
31+
.name("foo")
32+
.execute() != null
33+
34+
when:
35+
def appliedNamespace = Kubectl.apply(V1Namespace.class)
36+
.apiClient(apiClient)
37+
.resource(new V1Namespace()
38+
.apiVersion("v1")
39+
.kind("Namespace")
40+
.metadata(new V1ObjectMeta()
41+
.name("foo")
42+
.putAnnotationsItem("k", "v")))
43+
.execute()
44+
then:
45+
appliedNamespace != null
46+
Kubectl.get(V1Namespace.class)
47+
.apiClient(apiClient)
48+
.name("foo")
49+
.execute().metadata.getAnnotations().get("k") == "v"
50+
51+
when:
52+
def replacedNamespace = Kubectl.replace(V1Namespace.class)
53+
.apiClient(apiClient)
54+
.resource(new V1Namespace()
55+
.apiVersion("v1")
56+
.kind("Namespace")
57+
.metadata(new V1ObjectMeta()
58+
.name("foo")
59+
.putAnnotationsItem("k", "v2")))
60+
.execute()
61+
then:
62+
replacedNamespace != null
63+
Kubectl.get(V1Namespace.class)
64+
.apiClient(apiClient)
65+
.name("foo")
66+
.execute().metadata.getAnnotations().get("k") == "v2"
67+
68+
when:
69+
def deletedNamespace = Kubectl.delete(V1Namespace.class)
70+
.apiClient(apiClient)
71+
.name("foo")
72+
.execute()
73+
then:
74+
deletedNamespace != null
75+
76+
}
77+
78+
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class KubectlReplace<ApiType extends KubernetesObject>
2323
extends Kubectl.ResourceBuilder<ApiType, KubectlReplace<ApiType>>
2424
implements Kubectl.Executable<ApiType> {
2525
ApiType updateObject;
26-
UpdateOptions options;
26+
UpdateOptions options = new UpdateOptions();
2727

2828
KubectlReplace(Class<ApiType> apiTypeClass) {
2929
super(apiTypeClass);
@@ -69,9 +69,6 @@ public boolean isNamespaced(Class<ApiType> apiTypeClass) {
6969
}
7070

7171
private void verifyArguments() throws KubectlException {
72-
if (null == name) {
73-
throw new KubectlException("missing name argument");
74-
}
7572
if (null == updateObject) {
7673
throw new KubectlException("missing new resource");
7774
}

0 commit comments

Comments
 (0)