Skip to content

Commit eaf81e6

Browse files
committed
test : kubectl rollout history for daemonset
1 parent b47f10c commit eaf81e6

File tree

4 files changed

+728
-4
lines changed

4 files changed

+728
-4
lines changed

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

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@
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.patch;
19+
import static com.github.tomakehurst.wiremock.client.WireMock.patchRequestedFor;
20+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
1621
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
1722
import static org.junit.Assert.assertThrows;
1823

1924
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2025
import com.github.tomakehurst.wiremock.matching.EqualToPattern;
2126
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
2227
import io.kubernetes.client.openapi.ApiClient;
28+
import io.kubernetes.client.openapi.models.V1DaemonSet;
29+
import io.kubernetes.client.openapi.models.V1DaemonSetList;
2330
import io.kubernetes.client.openapi.models.V1Deployment;
31+
import io.kubernetes.client.openapi.models.V1DeploymentList;
2432
import io.kubernetes.client.util.ClientBuilder;
33+
import io.kubernetes.client.util.ModelMapper;
2534
import java.io.IOException;
2635
import java.nio.file.Files;
2736
import java.nio.file.Paths;
@@ -45,8 +54,33 @@ public class KubectlRolloutHistoryTest {
4554
.getResource("replicaset-list.json")
4655
.getPath();
4756

57+
private static final String DAEMON_SET =
58+
KubectlRolloutHistoryTest.class.getClassLoader().getResource("daemonset.json").getPath();
59+
60+
private static final String PATCHED_DAEMON_SET =
61+
KubectlRolloutHistoryTest.class
62+
.getClassLoader()
63+
.getResource("patched-daemonset.json")
64+
.getPath();
65+
66+
private static final String DAEMON_SET_CONTROLLER_REVISION_LIST =
67+
KubectlRolloutHistoryTest.class
68+
.getClassLoader()
69+
.getResource("daemonset-controllerrevision-list.json")
70+
.getPath();
71+
4872
@Before
4973
public void setup() throws IOException {
74+
ModelMapper.addModelMap(
75+
"apps",
76+
"v1",
77+
"Deployment",
78+
"deployments",
79+
true,
80+
V1Deployment.class,
81+
V1DeploymentList.class);
82+
ModelMapper.addModelMap(
83+
"apps", "v1", "DaemonSet", "daemonsets", true, V1DaemonSet.class, V1DaemonSetList.class);
5084
apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
5185
}
5286

@@ -68,7 +102,8 @@ public void testKubectlRolloutHistoryDeploymentShouldWork() throws KubectlExcept
68102
Kubectl.rolloutHistory(V1Deployment.class)
69103
.apiClient(apiClient)
70104
.name("foo")
71-
.namespace("default");
105+
.namespace("default")
106+
.skipDiscovery();
72107
rolloutHistory.execute();
73108
wireMockRule.verify(
74109
1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/deployments/foo"))));
@@ -99,7 +134,8 @@ public void testKubectlRolloutHistoryDeploymentWithRevisionShouldWork()
99134
.apiClient(apiClient)
100135
.name("foo")
101136
.namespace("default")
102-
.revision(3);
137+
.revision(3)
138+
.skipDiscovery();
103139
rolloutHistory.execute();
104140
wireMockRule.verify(
105141
1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/deployments/foo"))));
@@ -110,6 +146,82 @@ public void testKubectlRolloutHistoryDeploymentWithRevisionShouldWork()
110146
Assert.assertNotNull(rolloutHistory.getTemplate());
111147
}
112148

149+
@Test
150+
public void testKubectlRolloutHistoryDaemonSetShouldWork() throws KubectlException, IOException {
151+
wireMockRule.stubFor(
152+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))
153+
.willReturn(
154+
aResponse()
155+
.withStatus(200)
156+
.withBody(new String(Files.readAllBytes(Paths.get(DAEMON_SET))))));
157+
wireMockRule.stubFor(
158+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))
159+
.willReturn(
160+
aResponse()
161+
.withStatus(200)
162+
.withBody(
163+
new String(
164+
Files.readAllBytes(Paths.get(DAEMON_SET_CONTROLLER_REVISION_LIST))))));
165+
KubectlRolloutHistory<V1DaemonSet> rolloutHistory =
166+
Kubectl.rolloutHistory(V1DaemonSet.class)
167+
.apiClient(apiClient)
168+
.name("foo")
169+
.namespace("default")
170+
.skipDiscovery();
171+
rolloutHistory.execute();
172+
wireMockRule.verify(
173+
1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))));
174+
wireMockRule.verify(
175+
1,
176+
getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")))
177+
.withQueryParam("labelSelector", new EqualToPattern("app = bar")));
178+
Assert.assertEquals(3, rolloutHistory.getHistories().size());
179+
}
180+
181+
@Test
182+
public void testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork()
183+
throws KubectlException, IOException {
184+
wireMockRule.stubFor(
185+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))
186+
.willReturn(
187+
aResponse()
188+
.withStatus(200)
189+
.withBody(new String(Files.readAllBytes(Paths.get(DAEMON_SET))))));
190+
wireMockRule.stubFor(
191+
get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))
192+
.willReturn(
193+
aResponse()
194+
.withStatus(200)
195+
.withBody(
196+
new String(
197+
Files.readAllBytes(Paths.get(DAEMON_SET_CONTROLLER_REVISION_LIST))))));
198+
wireMockRule.stubFor(
199+
patch(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))
200+
.willReturn(
201+
aResponse()
202+
.withStatus(200)
203+
.withBody(new String(Files.readAllBytes(Paths.get(PATCHED_DAEMON_SET))))));
204+
KubectlRolloutHistory<V1DaemonSet> rolloutHistory =
205+
Kubectl.rolloutHistory(V1DaemonSet.class)
206+
.apiClient(apiClient)
207+
.name("foo")
208+
.namespace("default")
209+
.revision(2)
210+
.skipDiscovery();
211+
rolloutHistory.execute();
212+
wireMockRule.verify(
213+
1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))));
214+
wireMockRule.verify(
215+
1,
216+
getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")))
217+
.withQueryParam("labelSelector", new EqualToPattern("app = bar")));
218+
wireMockRule.verify(
219+
1,
220+
patchRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo")))
221+
.withQueryParam("dryRun", new EqualToPattern("All")));
222+
Assert.assertNotNull(rolloutHistory.getTemplate());
223+
}
224+
113225
@Test
114226
public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow() throws IOException {
115227
wireMockRule.stubFor(
@@ -129,7 +241,8 @@ public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow() throws IOE
129241
.apiClient(apiClient)
130242
.name("foo")
131243
.namespace("default")
132-
.revision(999);
244+
.revision(999)
245+
.skipDiscovery();
133246
assertThrows(KubectlException.class, rolloutHistory::execute);
134247
rolloutHistory.revision(-1);
135248
assertThrows(KubectlException.class, rolloutHistory::execute);

0 commit comments

Comments
 (0)