29
29
import io .kubernetes .client .openapi .models .V1DaemonSetList ;
30
30
import io .kubernetes .client .openapi .models .V1Deployment ;
31
31
import io .kubernetes .client .openapi .models .V1DeploymentList ;
32
+ import io .kubernetes .client .openapi .models .V1PodTemplate ;
32
33
import io .kubernetes .client .openapi .models .V1PodTemplateSpec ;
34
+ import io .kubernetes .client .openapi .models .V1StatefulSet ;
35
+ import io .kubernetes .client .openapi .models .V1StatefulSetList ;
33
36
import io .kubernetes .client .util .ClientBuilder ;
34
37
import io .kubernetes .client .util .ModelMapper ;
35
38
import java .io .IOException ;
@@ -65,6 +68,18 @@ public class KubectlRolloutTest {
65
68
.getResource ("daemonset-controllerrevision-list.json" )
66
69
.getPath ();
67
70
71
+ private static final String STATEFUL_SET =
72
+ KubectlRolloutTest .class .getClassLoader ().getResource ("statefulset.json" ).getPath ();
73
+
74
+ private static final String PATCHED_STATEFUL_SET =
75
+ KubectlRolloutTest .class .getClassLoader ().getResource ("patched-statefulset.json" ).getPath ();
76
+
77
+ private static final String STATEFUL_SET_CONTROLLER_REVISION_LIST =
78
+ KubectlRolloutTest .class
79
+ .getClassLoader ()
80
+ .getResource ("statefulset-controllerrevision-list.json" )
81
+ .getPath ();
82
+
68
83
@ Before
69
84
public void setup () throws IOException {
70
85
ModelMapper .addModelMap (
@@ -77,6 +92,14 @@ public void setup() throws IOException {
77
92
V1DeploymentList .class );
78
93
ModelMapper .addModelMap (
79
94
"apps" , "v1" , "DaemonSet" , "daemonsets" , true , V1DaemonSet .class , V1DaemonSetList .class );
95
+ ModelMapper .addModelMap (
96
+ "apps" ,
97
+ "v1" ,
98
+ "StatefulSet" ,
99
+ "statefulsets" ,
100
+ true ,
101
+ V1StatefulSet .class ,
102
+ V1StatefulSetList .class );
80
103
apiClient = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port ()).build ();
81
104
}
82
105
@@ -223,6 +246,87 @@ public void testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork()
223
246
Assert .assertNotNull (template );
224
247
}
225
248
249
+ @ Test
250
+ public void testKubectlRolloutHistoryStatefulSetShouldWork ()
251
+ throws KubectlException , IOException {
252
+ wireMockRule .stubFor (
253
+ get (urlPathEqualTo ("/apis/apps/v1/namespaces/default/statefulsets/foo" ))
254
+ .willReturn (
255
+ aResponse ()
256
+ .withStatus (200 )
257
+ .withBody (new String (Files .readAllBytes (Paths .get (STATEFUL_SET ))))));
258
+ wireMockRule .stubFor (
259
+ get (urlPathEqualTo ("/apis/apps/v1/namespaces/default/controllerrevisions" ))
260
+ .willReturn (
261
+ aResponse ()
262
+ .withStatus (200 )
263
+ .withBody (
264
+ new String (
265
+ Files .readAllBytes (
266
+ Paths .get (STATEFUL_SET_CONTROLLER_REVISION_LIST ))))));
267
+ List <History > histories =
268
+ Kubectl .rollout (V1StatefulSet .class )
269
+ .history ()
270
+ .apiClient (apiClient )
271
+ .name ("foo" )
272
+ .namespace ("default" )
273
+ .skipDiscovery ()
274
+ .execute ();
275
+ wireMockRule .verify (
276
+ 1 , getRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/statefulsets/foo" ))));
277
+ wireMockRule .verify (
278
+ 1 ,
279
+ getRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/controllerrevisions" )))
280
+ .withQueryParam ("labelSelector" , new EqualToPattern ("app = bar" )));
281
+ Assert .assertEquals (3 , histories .size ());
282
+ }
283
+
284
+ @ Test
285
+ public void testKubectlRolloutHistoryStatefulSetWithRevisionShouldWork ()
286
+ throws KubectlException , IOException {
287
+ wireMockRule .stubFor (
288
+ get (urlPathEqualTo ("/apis/apps/v1/namespaces/default/statefulsets/foo" ))
289
+ .willReturn (
290
+ aResponse ()
291
+ .withStatus (200 )
292
+ .withBody (new String (Files .readAllBytes (Paths .get (STATEFUL_SET ))))));
293
+ wireMockRule .stubFor (
294
+ get (urlPathEqualTo ("/apis/apps/v1/namespaces/default/controllerrevisions" ))
295
+ .willReturn (
296
+ aResponse ()
297
+ .withStatus (200 )
298
+ .withBody (
299
+ new String (
300
+ Files .readAllBytes (
301
+ Paths .get (STATEFUL_SET_CONTROLLER_REVISION_LIST ))))));
302
+ wireMockRule .stubFor (
303
+ patch (urlPathEqualTo ("/apis/apps/v1/namespaces/default/statefulsets/foo" ))
304
+ .willReturn (
305
+ aResponse ()
306
+ .withStatus (200 )
307
+ .withBody (new String (Files .readAllBytes (Paths .get (PATCHED_STATEFUL_SET ))))));
308
+ V1PodTemplateSpec template =
309
+ Kubectl .rollout (V1StatefulSet .class )
310
+ .history ()
311
+ .apiClient (apiClient )
312
+ .name ("foo" )
313
+ .namespace ("default" )
314
+ .revision (2 )
315
+ .skipDiscovery ()
316
+ .execute ();
317
+ wireMockRule .verify (
318
+ 1 , getRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/statefulsets/foo" ))));
319
+ wireMockRule .verify (
320
+ 1 ,
321
+ getRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/controllerrevisions" )))
322
+ .withQueryParam ("labelSelector" , new EqualToPattern ("app = bar" )));
323
+ wireMockRule .verify (
324
+ 1 ,
325
+ patchRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/statefulsets/foo" )))
326
+ .withQueryParam ("dryRun" , new EqualToPattern ("All" )));
327
+ Assert .assertNotNull (template );
328
+ }
329
+
226
330
@ Test
227
331
public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow () throws IOException {
228
332
wireMockRule .stubFor (
0 commit comments