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