Skip to content

Commit a0e4771

Browse files
committed
test : kubectl rollout history for daemonset
1 parent 2f8d925 commit a0e4771

File tree

3 files changed

+519
-1
lines changed

3 files changed

+519
-1
lines changed

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutHistoryTest.java

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
*/
1313
package io.kubernetes.client.extended.kubectl;
1414

15-
import static com.github.tomakehurst.wiremock.client.WireMock.*;
15+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
16+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
17+
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
18+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
1619
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
1720
import static org.junit.Assert.assertThrows;
1821

1922
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2023
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
2124
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
2225
import io.kubernetes.client.openapi.ApiClient;
26+
import io.kubernetes.client.openapi.models.V1DaemonSet;
2327
import io.kubernetes.client.openapi.models.V1Deployment;
2428
import io.kubernetes.client.util.ClientBuilder;
2529
import java.io.IOException;
@@ -45,6 +49,15 @@ public class KubectlRolloutHistoryTest {
4549
.getResource("replicaset-list.json")
4650
.getPath();
4751

52+
private static final String DAEMON_SET =
53+
KubectlRolloutHistoryTest.class.getClassLoader().getResource("daemonset.json").getPath();
54+
55+
private static final String DAEMON_SET_CONTROLLER_REVISION_LIST =
56+
KubectlRolloutHistoryTest.class
57+
.getClassLoader()
58+
.getResource("daemonset-controllerrevision-list.json")
59+
.getPath();
60+
4861
@Before
4962
public void setup() throws IOException {
5063
apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
@@ -110,6 +123,70 @@ public void testKubectlRolloutHistoryDeploymentWithRevisionShouldWork()
110123
Assert.assertNotNull(rolloutHistory.getTemplate());
111124
}
112125

126+
@Test
127+
public void testKubectlRolloutHistoryDaemonSetShouldWork() throws KubectlException, IOException {
128+
wireMockRule.stubFor(
129+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))
130+
.willReturn(
131+
aResponse()
132+
.withStatus(200)
133+
.withBody(new String(Files.readAllBytes(Paths.get(DAEMON_SET))))));
134+
wireMockRule.stubFor(
135+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))
136+
.willReturn(
137+
aResponse()
138+
.withStatus(200)
139+
.withBody(
140+
new String(
141+
Files.readAllBytes(Paths.get(DAEMON_SET_CONTROLLER_REVISION_LIST))))));
142+
KubectlRolloutHistory<V1DaemonSet> rolloutHistory =
143+
Kubectl.rolloutHistory(V1DaemonSet.class)
144+
.apiClient(apiClient)
145+
.name("foo")
146+
.namespace("default");
147+
rolloutHistory.execute();
148+
wireMockRule.verify(
149+
1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))));
150+
wireMockRule.verify(
151+
1,
152+
getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")))
153+
.withQueryParam("labelSelector", new EqualToPattern("app = bar")));
154+
Assert.assertEquals(3, rolloutHistory.getHistories().size());
155+
}
156+
157+
@Test
158+
public void testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork()
159+
throws KubectlException, IOException {
160+
wireMockRule.stubFor(
161+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))
162+
.willReturn(
163+
aResponse()
164+
.withStatus(200)
165+
.withBody(new String(Files.readAllBytes(Paths.get(DAEMON_SET))))));
166+
wireMockRule.stubFor(
167+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))
168+
.willReturn(
169+
aResponse()
170+
.withStatus(200)
171+
.withBody(
172+
new String(
173+
Files.readAllBytes(Paths.get(DAEMON_SET_CONTROLLER_REVISION_LIST))))));
174+
KubectlRolloutHistory<V1DaemonSet> rolloutHistory =
175+
Kubectl.rolloutHistory(V1DaemonSet.class)
176+
.apiClient(apiClient)
177+
.name("foo")
178+
.namespace("default")
179+
.revision(2);
180+
rolloutHistory.execute();
181+
wireMockRule.verify(
182+
1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))));
183+
wireMockRule.verify(
184+
1,
185+
getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")))
186+
.withQueryParam("labelSelector", new EqualToPattern("app = bar")));
187+
Assert.assertNotNull(rolloutHistory.getTemplate());
188+
}
189+
113190
@Test
114191
public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow() throws IOException {
115192
wireMockRule.stubFor(
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
{
2+
"apiVersion": "apps/v1",
3+
"items": [{
4+
"data": {
5+
"spec": {
6+
"template": {
7+
"$patch": "replace",
8+
"metadata": {
9+
"labels": {
10+
"app": "bar"
11+
}
12+
},
13+
"spec": {
14+
"containers": [{
15+
"args": ["1000"],
16+
"command": ["sleep"],
17+
"image": "busybox:1.31.1",
18+
"imagePullPolicy": "IfNotPresent",
19+
"name": "busybox-host",
20+
"resources": {},
21+
"terminationMessagePath": "/dev/termination-log",
22+
"terminationMessagePolicy": "File"
23+
}],
24+
"dnsPolicy": "ClusterFirst",
25+
"restartPolicy": "Always",
26+
"schedulerName": "default-scheduler",
27+
"securityContext": {},
28+
"terminationGracePeriodSeconds": 30.0
29+
}
30+
}
31+
}
32+
},
33+
"metadata": {
34+
"annotations": {
35+
"deprecated.daemonset.template.generation": "1",
36+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"DaemonSet\",\"metadata\":{\"annotations\":{\"kubernetes.io/change-cause\":\"kubectl.exe apply --filename\u003d./daemonSet.Yaml --record\u003dtrue\"},\"name\":\"foo\",\"namespace\":\"default\"},\"spec\":{\"selector\":{\"matchLabels\":{\"app\":\"bar\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"bar\"}},\"spec\":{\"containers\":[{\"args\":[\"1000\"],\"command\":[\"sleep\"],\"image\":\"busybox:1.31.1\",\"name\":\"busybox-host\"}]}}}}\n",
37+
"kubernetes.io/change-cause": "kubectl.exe apply --filename\u003d./daemonSet.Yaml --record\u003dtrue"
38+
},
39+
"creationTimestamp": "2021-08-13T07:13:06.000000Z",
40+
"labels": {
41+
"app": "bar",
42+
"controller-revision-hash": "69b77bc98d"
43+
},
44+
"managedFields": [{
45+
"apiVersion": "apps/v1",
46+
"fieldsType": "FieldsV1",
47+
"fieldsV1": {
48+
"f:data": {},
49+
"f:metadata": {
50+
"f:annotations": {
51+
".": {},
52+
"f:deprecated.daemonset.template.generation": {},
53+
"f:kubectl.kubernetes.io/last-applied-configuration": {},
54+
"f:kubernetes.io/change-cause": {}
55+
},
56+
"f:labels": {
57+
".": {},
58+
"f:app": {},
59+
"f:controller-revision-hash": {}
60+
},
61+
"f:ownerReferences": {
62+
".": {},
63+
"k:{\"uid\":\"d3774f2a-e492-4968-a888-23b71e4c13a9\"}": {
64+
".": {},
65+
"f:apiVersion": {},
66+
"f:blockOwnerDeletion": {},
67+
"f:controller": {},
68+
"f:kind": {},
69+
"f:name": {},
70+
"f:uid": {}
71+
}
72+
}
73+
},
74+
"f:revision": {}
75+
},
76+
"manager": "kube-controller-manager",
77+
"operation": "Update",
78+
"time": "2021-08-13T07:13:06.000000Z"
79+
}],
80+
"name": "foo-69b77bc98d",
81+
"namespace": "default",
82+
"ownerReferences": [{
83+
"apiVersion": "apps/v1",
84+
"blockOwnerDeletion": true,
85+
"controller": true,
86+
"kind": "DaemonSet",
87+
"name": "foo",
88+
"uid": "d3774f2a-e492-4968-a888-23b71e4c13a9"
89+
}],
90+
"resourceVersion": "96595",
91+
"uid": "e684a7d1-34c1-4f59-8ebe-f026f5fb9910"
92+
},
93+
"revision": 1
94+
}, {
95+
"data": {
96+
"spec": {
97+
"template": {
98+
"$patch": "replace",
99+
"metadata": {
100+
"annotations": {
101+
"kubectl.kubernetes.io/restartedAt": "2021-08-13T16:53:21+08:00"
102+
},
103+
"labels": {
104+
"app": "bar"
105+
}
106+
},
107+
"spec": {
108+
"containers": [{
109+
"args": ["1000"],
110+
"command": ["sleep"],
111+
"image": "busybox:1.31.1",
112+
"imagePullPolicy": "IfNotPresent",
113+
"name": "busybox-host",
114+
"resources": {},
115+
"terminationMessagePath": "/dev/termination-log",
116+
"terminationMessagePolicy": "File"
117+
}],
118+
"dnsPolicy": "ClusterFirst",
119+
"restartPolicy": "Always",
120+
"schedulerName": "default-scheduler",
121+
"securityContext": {},
122+
"terminationGracePeriodSeconds": 30.0
123+
}
124+
}
125+
}
126+
},
127+
"metadata": {
128+
"annotations": {
129+
"deprecated.daemonset.template.generation": "3",
130+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"DaemonSet\",\"metadata\":{\"annotations\":{},\"name\":\"foo\",\"namespace\":\"default\"},\"spec\":{\"selector\":{\"matchLabels\":{\"app\":\"bar\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"bar\"}},\"spec\":{\"containers\":[{\"args\":[\"1000\"],\"command\":[\"sleep\"],\"image\":\"busybox:1.31.1\",\"name\":\"busybox-host\"}]}}}}\n"
131+
},
132+
"creationTimestamp": "2021-08-13T08:53:21.000000Z",
133+
"labels": {
134+
"app": "bar",
135+
"controller-revision-hash": "797f8dc6b5"
136+
},
137+
"managedFields": [{
138+
"apiVersion": "apps/v1",
139+
"fieldsType": "FieldsV1",
140+
"fieldsV1": {
141+
"f:data": {},
142+
"f:metadata": {
143+
"f:annotations": {
144+
".": {},
145+
"f:deprecated.daemonset.template.generation": {},
146+
"f:kubectl.kubernetes.io/last-applied-configuration": {}
147+
},
148+
"f:labels": {
149+
".": {},
150+
"f:app": {},
151+
"f:controller-revision-hash": {}
152+
},
153+
"f:ownerReferences": {
154+
".": {},
155+
"k:{\"uid\":\"d3774f2a-e492-4968-a888-23b71e4c13a9\"}": {
156+
".": {},
157+
"f:apiVersion": {},
158+
"f:blockOwnerDeletion": {},
159+
"f:controller": {},
160+
"f:kind": {},
161+
"f:name": {},
162+
"f:uid": {}
163+
}
164+
}
165+
},
166+
"f:revision": {}
167+
},
168+
"manager": "kube-controller-manager",
169+
"operation": "Update",
170+
"time": "2021-08-13T08:53:21.000000Z"
171+
}],
172+
"name": "foo-797f8dc6b5",
173+
"namespace": "default",
174+
"ownerReferences": [{
175+
"apiVersion": "apps/v1",
176+
"blockOwnerDeletion": true,
177+
"controller": true,
178+
"kind": "DaemonSet",
179+
"name": "foo",
180+
"uid": "d3774f2a-e492-4968-a888-23b71e4c13a9"
181+
}],
182+
"resourceVersion": "101207",
183+
"uid": "37be558a-ba1e-4182-bc5a-ca0ed324cdf7"
184+
},
185+
"revision": 3
186+
}, {
187+
"data": {
188+
"spec": {
189+
"template": {
190+
"$patch": "replace",
191+
"metadata": {
192+
"annotations": {
193+
"kubectl.kubernetes.io/restartedAt": "2021-08-13T15:14:35+08:00"
194+
},
195+
"labels": {
196+
"app": "bar"
197+
}
198+
},
199+
"spec": {
200+
"containers": [{
201+
"args": ["1000"],
202+
"command": ["sleep"],
203+
"image": "busybox:1.31.1",
204+
"imagePullPolicy": "IfNotPresent",
205+
"name": "busybox-host",
206+
"resources": {},
207+
"terminationMessagePath": "/dev/termination-log",
208+
"terminationMessagePolicy": "File"
209+
}],
210+
"dnsPolicy": "ClusterFirst",
211+
"restartPolicy": "Always",
212+
"schedulerName": "default-scheduler",
213+
"securityContext": {},
214+
"terminationGracePeriodSeconds": 30.0
215+
}
216+
}
217+
}
218+
},
219+
"metadata": {
220+
"annotations": {
221+
"deprecated.daemonset.template.generation": "2",
222+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"DaemonSet\",\"metadata\":{\"annotations\":{\"kubernetes.io/change-cause\":\"kubectl.exe apply --filename\u003d./daemonSet.Yaml --record\u003dtrue\"},\"name\":\"foo\",\"namespace\":\"default\"},\"spec\":{\"selector\":{\"matchLabels\":{\"app\":\"bar\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"bar\"}},\"spec\":{\"containers\":[{\"args\":[\"1000\"],\"command\":[\"sleep\"],\"image\":\"busybox:1.31.1\",\"name\":\"busybox-host\"}]}}}}\n",
223+
"kubernetes.io/change-cause": "kubectl.exe apply --filename\u003d./daemonSet.Yaml --record\u003dtrue"
224+
},
225+
"creationTimestamp": "2021-08-13T07:14:35.000000Z",
226+
"labels": {
227+
"app": "bar",
228+
"controller-revision-hash": "7f9dcff8b8"
229+
},
230+
"managedFields": [{
231+
"apiVersion": "apps/v1",
232+
"fieldsType": "FieldsV1",
233+
"fieldsV1": {
234+
"f:data": {},
235+
"f:metadata": {
236+
"f:annotations": {
237+
".": {},
238+
"f:deprecated.daemonset.template.generation": {},
239+
"f:kubectl.kubernetes.io/last-applied-configuration": {},
240+
"f:kubernetes.io/change-cause": {}
241+
},
242+
"f:labels": {
243+
".": {},
244+
"f:app": {},
245+
"f:controller-revision-hash": {}
246+
},
247+
"f:ownerReferences": {
248+
".": {},
249+
"k:{\"uid\":\"d3774f2a-e492-4968-a888-23b71e4c13a9\"}": {
250+
".": {},
251+
"f:apiVersion": {},
252+
"f:blockOwnerDeletion": {},
253+
"f:controller": {},
254+
"f:kind": {},
255+
"f:name": {},
256+
"f:uid": {}
257+
}
258+
}
259+
},
260+
"f:revision": {}
261+
},
262+
"manager": "kube-controller-manager",
263+
"operation": "Update",
264+
"time": "2021-08-13T07:14:35.000000Z"
265+
}],
266+
"name": "foo-7f9dcff8b8",
267+
"namespace": "default",
268+
"ownerReferences": [{
269+
"apiVersion": "apps/v1",
270+
"blockOwnerDeletion": true,
271+
"controller": true,
272+
"kind": "DaemonSet",
273+
"name": "foo",
274+
"uid": "d3774f2a-e492-4968-a888-23b71e4c13a9"
275+
}],
276+
"resourceVersion": "96669",
277+
"uid": "b8f45530-23a9-4fea-94b5-778f65117c43"
278+
},
279+
"revision": 2
280+
}],
281+
"kind": "ControllerRevisionList",
282+
"metadata": {
283+
"resourceVersion": "101602"
284+
}
285+
}

0 commit comments

Comments
 (0)