@@ -24,9 +24,12 @@ import (
24
24
v1 "k8s.io/api/core/v1"
25
25
networkingv1 "k8s.io/api/networking/v1"
26
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
+ types "k8s.io/apimachinery/pkg/types"
27
28
"k8s.io/apimachinery/pkg/util/intstr"
28
29
"k8s.io/apimachinery/pkg/util/wait"
29
30
clientset "k8s.io/client-go/kubernetes"
31
+ "k8s.io/client-go/util/retry"
32
+ "k8s.io/kubernetes/pkg/controlplane/controller/defaultservicecidr"
30
33
"k8s.io/kubernetes/test/e2e/framework"
31
34
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
32
35
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
@@ -142,3 +145,196 @@ func isReady(serviceCIDR *networkingv1.ServiceCIDR) bool {
142
145
}
143
146
return false
144
147
}
148
+
149
+ var _ = common .SIGDescribe ("ServiceCIDR and IPAddress API" , func () {
150
+ f := framework .NewDefaultFramework ("servicecidr" )
151
+ f .NamespacePodSecurityLevel = admissionapi .LevelPrivileged
152
+ /*
153
+ Release: v1.34
154
+ Testname: ServiceCIDR API
155
+ Description:
156
+ The networking.k8s.io API group MUST exist in the /apis discovery document.
157
+ The networking.k8s.io/v1 API group/version MUST exist in the /apis/networking.k8s.io discovery document.
158
+ The servicecidrs resources MUST exist in the /apis/networking.k8s.io/v1 discovery document.
159
+ The servicecidrs resource must support create, get, list, watch, update, patch, delete, and deletecollection.
160
+ The servicecidrs/status resource must support update and patch
161
+ */
162
+
163
+ framework .ConformanceIt ("should support ServiceCIDR API operations" , func (ctx context.Context ) {
164
+ ginkgo .By ("getting" )
165
+ _ , err := f .ClientSet .NetworkingV1 ().ServiceCIDRs ().Get (ctx , defaultservicecidr .DefaultServiceCIDRName , metav1.GetOptions {})
166
+ if err != nil {
167
+ framework .Failf ("unexpected error getting default ServiceCIDR: %v" , err )
168
+ }
169
+
170
+ ginkgo .By ("patching" )
171
+ patchedServiceCIDR , err := f .ClientSet .NetworkingV1 ().ServiceCIDRs ().Patch (ctx , defaultservicecidr .DefaultServiceCIDRName , types .MergePatchType , []byte (`{"metadata":{"annotations":{"patched":"true"}}}` ), metav1.PatchOptions {})
172
+ if err != nil {
173
+ framework .Failf ("unexpected error patching IPAddress: %v" , err )
174
+ }
175
+ if v , ok := patchedServiceCIDR .Annotations ["patched" ]; ! ok || v != "true" {
176
+ framework .Failf ("patched object should have the applied annotation" )
177
+ }
178
+
179
+ ginkgo .By ("updating" )
180
+ var cidrToUpdate , updatedCIDR * networkingv1.ServiceCIDR
181
+ err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
182
+ cidrToUpdate , err = f .ClientSet .NetworkingV1 ().ServiceCIDRs ().Get (ctx , defaultservicecidr .DefaultServiceCIDRName , metav1.GetOptions {})
183
+ if err != nil {
184
+ return err
185
+ }
186
+ cidrToUpdate .Annotations ["updated" ] = "true"
187
+ updatedCIDR , err = f .ClientSet .NetworkingV1 ().ServiceCIDRs ().Update (ctx , cidrToUpdate , metav1.UpdateOptions {})
188
+ return err
189
+ })
190
+ if err != nil {
191
+ framework .Failf ("unexpected error updating IPAddress: %v" , err )
192
+ }
193
+ if v , ok := updatedCIDR .Annotations ["updated" ]; ! ok || v != "true" {
194
+ framework .Failf ("updated object should have the applied annotation" )
195
+ }
196
+
197
+ ginkgo .By ("listing" )
198
+ list , err := f .ClientSet .NetworkingV1 ().ServiceCIDRs ().List (ctx , metav1.ListOptions {})
199
+ if err != nil {
200
+ framework .Failf ("unexpected error listing ServiceCIDR: %v" , err )
201
+ }
202
+ if len (list .Items ) == 0 {
203
+ framework .Failf ("expected at list one, the default, ServiceCIDR" )
204
+ }
205
+
206
+ ginkgo .By ("watching" )
207
+ _ , err = f .ClientSet .NetworkingV1 ().ServiceCIDRs ().Watch (ctx , metav1.ListOptions {})
208
+ if err != nil {
209
+ framework .Failf ("unexpected error watching ServiceCIDR: %v" , err )
210
+ }
211
+
212
+ })
213
+
214
+ /*
215
+ Release: v1.34
216
+ Testname: IPAddress API
217
+ Description:
218
+ The networking.k8s.io API group MUST exist in the /apis discovery document.
219
+ The networking.k8s.io/v1 API group/version MUST exist in the /apis/networking.k8s.io discovery document.
220
+ The ipaddresses resources MUST exist in the /apis/networking.k8s.io/v1 discovery document.
221
+ The ipaddresses resource must support create, get, list, watch, update, patch, delete, and deletecollection.
222
+ */
223
+ framework .ConformanceIt ("should support IPAddress API operations" , func (ctx context.Context ) {
224
+ ip := & networkingv1.IPAddress {
225
+ ObjectMeta : metav1.ObjectMeta {
226
+ Name : "255.255.255.255" ,
227
+ Labels : map [string ]string {
228
+ "type" : "broadcast" ,
229
+ },
230
+ },
231
+ Spec : networkingv1.IPAddressSpec {
232
+ ParentRef : & networkingv1.ParentReference {
233
+ Group : "mygroup" ,
234
+ Resource : "myresources" ,
235
+ Namespace : "foo" ,
236
+ Name : "bar" ,
237
+ },
238
+ },
239
+ }
240
+
241
+ ipv6 := & networkingv1.IPAddress {
242
+ ObjectMeta : metav1.ObjectMeta {
243
+ Name : "fe80::42:1dff:fe84:f9e2" ,
244
+ Labels : map [string ]string {
245
+ "type" : "link-local" ,
246
+ },
247
+ },
248
+ Spec : networkingv1.IPAddressSpec {
249
+ ParentRef : & networkingv1.ParentReference {
250
+ Group : "mygroup" ,
251
+ Resource : "myresources" ,
252
+ Namespace : "foo" ,
253
+ Name : "bar" ,
254
+ },
255
+ },
256
+ }
257
+
258
+ ginkgo .By ("creating" )
259
+ _ , err := f .ClientSet .NetworkingV1 ().IPAddresses ().Create (ctx , ip , metav1.CreateOptions {})
260
+ if err != nil {
261
+ framework .Failf ("unexpected error getting IPAddress: %v" , err )
262
+ }
263
+ _ , err = f .ClientSet .NetworkingV1 ().IPAddresses ().Create (ctx , ipv6 , metav1.CreateOptions {})
264
+ if err != nil {
265
+ framework .Failf ("unexpected error getting IPAddress: %v" , err )
266
+ }
267
+
268
+ ginkgo .By ("patching" )
269
+ patchedIP , err := f .ClientSet .NetworkingV1 ().IPAddresses ().Patch (ctx , ip .Name , types .MergePatchType , []byte (`{"metadata":{"annotations":{"patched":"true"}}}` ), metav1.PatchOptions {})
270
+ if err != nil {
271
+ framework .Failf ("unexpected error patching IPAddress: %v" , err )
272
+ }
273
+ if v , ok := patchedIP .Annotations ["patched" ]; ! ok || v != "true" {
274
+ framework .Failf ("patched object should have the applied annotation" )
275
+ }
276
+
277
+ ginkgo .By ("updating" )
278
+ var ipToUpdate , updatedIP * networkingv1.IPAddress
279
+ err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
280
+ ipToUpdate , err = f .ClientSet .NetworkingV1 ().IPAddresses ().Get (ctx , ip .Name , metav1.GetOptions {})
281
+ if err != nil {
282
+ return err
283
+ }
284
+ ipToUpdate .Annotations ["updated" ] = "true"
285
+ updatedIP , err = f .ClientSet .NetworkingV1 ().IPAddresses ().Update (ctx , ipToUpdate , metav1.UpdateOptions {})
286
+ return err
287
+ })
288
+ if err != nil {
289
+ framework .Failf ("unexpected error updating IPAddress: %v" , err )
290
+ }
291
+ if v , ok := updatedIP .Annotations ["updated" ]; ! ok || v != "true" {
292
+ framework .Failf ("updated object should have the applied annotation" )
293
+ }
294
+
295
+ ginkgo .By ("getting" )
296
+ _ , err = f .ClientSet .NetworkingV1 ().IPAddresses ().Get (ctx , ip .Name , metav1.GetOptions {})
297
+ if err != nil {
298
+ framework .Failf ("unexpected error getting IPAddress: %v" , err )
299
+ }
300
+
301
+ ginkgo .By ("listing" )
302
+ list , err := f .ClientSet .NetworkingV1 ().IPAddresses ().List (ctx , metav1.ListOptions {
303
+ LabelSelector : "type=broadcast" ,
304
+ })
305
+ if err != nil {
306
+ framework .Failf ("unexpected error listing IPAddress: %v" , err )
307
+ }
308
+ if len (list .Items ) != 1 {
309
+ framework .Failf ("expected one IPAddress" )
310
+ }
311
+
312
+ ginkgo .By ("watching" )
313
+ _ , err = f .ClientSet .NetworkingV1 ().IPAddresses ().Watch (ctx , metav1.ListOptions {
314
+ LabelSelector : "type=broadcast" ,
315
+ })
316
+ if err != nil {
317
+ framework .Failf ("unexpected error watching IPAddress: %v" , err )
318
+ }
319
+ ginkgo .By ("deleting" )
320
+ err = f .ClientSet .NetworkingV1 ().IPAddresses ().Delete (ctx , ip .Name , metav1.DeleteOptions {})
321
+ if err != nil {
322
+ framework .Failf ("unexpected error deleting IPAddress: %v" , err )
323
+ }
324
+
325
+ ginkgo .By ("deleting a collection" )
326
+ err = f .ClientSet .NetworkingV1 ().IPAddresses ().DeleteCollection (ctx , metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : "type=link-local" })
327
+ if err != nil {
328
+ framework .Failf ("unexpected error deleting IPAddress Collection: %v" , err )
329
+ }
330
+ list , err = f .ClientSet .NetworkingV1 ().IPAddresses ().List (ctx , metav1.ListOptions {
331
+ LabelSelector : "type=link-local" ,
332
+ })
333
+ if err != nil {
334
+ framework .Failf ("unexpected error listing IPAddress: %v" , err )
335
+ }
336
+ if len (list .Items ) > 0 {
337
+ framework .Failf ("expected 0 IPAddresses" )
338
+ }
339
+ })
340
+ })
0 commit comments