12
12
*/
13
13
package io .kubernetes .client .extended .kubectl ;
14
14
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 ;
16
21
import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
17
22
import static org .junit .Assert .assertThrows ;
18
23
19
24
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
20
25
import com .github .tomakehurst .wiremock .matching .EqualToPattern ;
21
26
import io .kubernetes .client .extended .kubectl .exception .KubectlException ;
22
27
import io .kubernetes .client .openapi .ApiClient ;
28
+ import io .kubernetes .client .openapi .models .V1DaemonSet ;
29
+ import io .kubernetes .client .openapi .models .V1DaemonSetList ;
23
30
import io .kubernetes .client .openapi .models .V1Deployment ;
31
+ import io .kubernetes .client .openapi .models .V1DeploymentList ;
24
32
import io .kubernetes .client .util .ClientBuilder ;
33
+ import io .kubernetes .client .util .ModelMapper ;
25
34
import java .io .IOException ;
26
35
import java .nio .file .Files ;
27
36
import java .nio .file .Paths ;
@@ -45,8 +54,33 @@ public class KubectlRolloutHistoryTest {
45
54
.getResource ("replicaset-list.json" )
46
55
.getPath ();
47
56
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
+
48
72
@ Before
49
73
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 );
50
84
apiClient = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port ()).build ();
51
85
}
52
86
@@ -68,7 +102,8 @@ public void testKubectlRolloutHistoryDeploymentShouldWork() throws KubectlExcept
68
102
Kubectl .rolloutHistory (V1Deployment .class )
69
103
.apiClient (apiClient )
70
104
.name ("foo" )
71
- .namespace ("default" );
105
+ .namespace ("default" )
106
+ .skipDiscovery ();
72
107
rolloutHistory .execute ();
73
108
wireMockRule .verify (
74
109
1 , getRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/deployments/foo" ))));
@@ -99,7 +134,8 @@ public void testKubectlRolloutHistoryDeploymentWithRevisionShouldWork()
99
134
.apiClient (apiClient )
100
135
.name ("foo" )
101
136
.namespace ("default" )
102
- .revision (3 );
137
+ .revision (3 )
138
+ .skipDiscovery ();
103
139
rolloutHistory .execute ();
104
140
wireMockRule .verify (
105
141
1 , getRequestedFor ((urlPathEqualTo ("/apis/apps/v1/namespaces/default/deployments/foo" ))));
@@ -110,6 +146,82 @@ public void testKubectlRolloutHistoryDeploymentWithRevisionShouldWork()
110
146
Assert .assertNotNull (rolloutHistory .getTemplate ());
111
147
}
112
148
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
+
113
225
@ Test
114
226
public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow () throws IOException {
115
227
wireMockRule .stubFor (
@@ -129,7 +241,8 @@ public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow() throws IOE
129
241
.apiClient (apiClient )
130
242
.name ("foo" )
131
243
.namespace ("default" )
132
- .revision (999 );
244
+ .revision (999 )
245
+ .skipDiscovery ();
133
246
assertThrows (KubectlException .class , rolloutHistory ::execute );
134
247
rolloutHistory .revision (-1 );
135
248
assertThrows (KubectlException .class , rolloutHistory ::execute );
0 commit comments