You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// +kubebuilder:validation:XValidation:rule="has(self.intervalInSeconds) && self.intervalInSeconds == 30 ? (!has(self.timeoutInSeconds) || (self.timeoutInSeconds >= 5 && self.timeoutInSeconds <= 10)) : true",message="timeoutInSeconds must be between 5 and 10 when intervalInSeconds is 30"
61
+
// +kubebuilder:validation:XValidation:rule="has(self.intervalInSeconds) && self.intervalInSeconds == 10 ? (!has(self.timeoutInSeconds) || (self.timeoutInSeconds >= 5 && self.timeoutInSeconds <= 9)) : true",message="timeoutInSeconds must be between 5 and 9 when intervalInSeconds is 10"
60
62
typeMonitorConfigstruct {
61
63
// The monitor interval for endpoints in this profile. This is the interval at which Traffic Manager will check the health
It("Update the trafficManagerProfile spec", func() {
158
+
It("Update the trafficManagerProfile spec and should fail", func() {
159
159
Expect(k8sClient.Get(ctx, types.NamespacedName{Namespace: testNamespace, Name: name}, profile)).Should(Succeed(), "failed to get the trafficManagerProfile")
Copy file name to clipboardExpand all lines: test/apis/v1beta1/api_validation_integration_test.go
+236Lines changed: 236 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -179,6 +179,110 @@ var _ = Describe("Test networking v1alpha1 API validation", func() {
179
179
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile")
180
180
})
181
181
182
+
It("should deny creating API with timeoutInSeconds < 5 when intervalInSeconds is 30", func() {
183
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
184
+
ObjectMeta: objectMetaWithNameValid,
185
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
186
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
187
+
IntervalInSeconds: ptr.To(int64(30)),
188
+
TimeoutInSeconds: ptr.To(int64(4)),
189
+
},
190
+
ResourceGroup: "test-resource-group",
191
+
},
192
+
}
193
+
By("expecting denial of CREATE API with invalid timeoutInSeconds")
194
+
varerr=hubClient.Create(ctx, profile)
195
+
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
196
+
Expect(statusErr.Status().Message).Should(ContainSubstring("spec.monitorConfig.timeoutInSeconds in body should be greater than or equal to 5"))
197
+
Expect(statusErr.Status().Message).Should(ContainSubstring("timeoutInSeconds must be between 5 and 10 when intervalInSeconds is 30"))
198
+
})
199
+
200
+
It("should deny creating API with timeoutInSeconds > 10 when intervalInSeconds is 30", func() {
201
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
202
+
ObjectMeta: objectMetaWithNameValid,
203
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
204
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
205
+
IntervalInSeconds: ptr.To(int64(30)),
206
+
TimeoutInSeconds: ptr.To(int64(15)),
207
+
},
208
+
ResourceGroup: "test-resource-group",
209
+
},
210
+
}
211
+
By("expecting denial of CREATE API with invalid timeoutInSeconds")
212
+
varerr=hubClient.Create(ctx, profile)
213
+
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
214
+
Expect(statusErr.Status().Message).Should(ContainSubstring("spec.monitorConfig.timeoutInSeconds in body should be less than or equal to 10"))
215
+
Expect(statusErr.Status().Message).Should(ContainSubstring("timeoutInSeconds must be between 5 and 10 when intervalInSeconds is 30"))
216
+
})
217
+
218
+
It("should deny creating API with timeoutInSeconds < 5 when intervalInSeconds is 10", func() {
219
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
220
+
ObjectMeta: objectMetaWithNameValid,
221
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
222
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
223
+
IntervalInSeconds: ptr.To(int64(10)),
224
+
TimeoutInSeconds: ptr.To(int64(4)),
225
+
},
226
+
ResourceGroup: "test-resource-group",
227
+
},
228
+
}
229
+
By("expecting denial of CREATE API with invalid timeoutInSeconds")
230
+
varerr=hubClient.Create(ctx, profile)
231
+
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
232
+
Expect(statusErr.Status().Message).Should(ContainSubstring("spec.monitorConfig.timeoutInSeconds in body should be greater than or equal to 5"))
233
+
Expect(statusErr.Status().Message).Should(ContainSubstring("timeoutInSeconds must be between 5 and 9 when intervalInSeconds is 10"))
234
+
})
235
+
236
+
It("should deny creating API with timeoutInSeconds > 9 when intervalInSeconds is 10", func() {
237
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
238
+
ObjectMeta: objectMetaWithNameValid,
239
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
240
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
241
+
IntervalInSeconds: ptr.To(int64(10)),
242
+
TimeoutInSeconds: ptr.To(int64(10)),
243
+
},
244
+
ResourceGroup: "test-resource-group",
245
+
},
246
+
}
247
+
By("expecting denial of CREATE API with invalid timeoutInSeconds")
248
+
varerr=hubClient.Create(ctx, profile)
249
+
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
250
+
Expect(statusErr.Status().Message).Should(ContainSubstring("spec.monitorConfig: Invalid value: \"object\": timeoutInSeconds must be between 5 and 9 when intervalInSeconds is 10"))
251
+
})
252
+
253
+
It("should deny creating API with timeoutInSeconds < 5 when intervalInSeconds is not defined", func() {
254
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
255
+
ObjectMeta: objectMetaWithNameValid,
256
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
257
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
258
+
TimeoutInSeconds: ptr.To(int64(3)),
259
+
},
260
+
ResourceGroup: "test-resource-group",
261
+
},
262
+
}
263
+
By("expecting denial of CREATE API with invalid timeoutInSeconds")
264
+
varerr=hubClient.Create(ctx, profile)
265
+
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
266
+
Expect(statusErr.Status().Message).Should(ContainSubstring("spec.monitorConfig.timeoutInSeconds in body should be greater than or equal to 5"))
267
+
Expect(statusErr.Status().Message).Should(ContainSubstring("timeoutInSeconds must be between 5 and 10 when intervalInSeconds is 30"))
268
+
})
269
+
270
+
It("should deny creating API with timeoutInSeconds > 10 when intervalInSeconds is not defined", func() {
271
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
272
+
ObjectMeta: objectMetaWithNameValid,
273
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
274
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
275
+
TimeoutInSeconds: ptr.To(int64(11)),
276
+
},
277
+
ResourceGroup: "test-resource-group",
278
+
},
279
+
}
280
+
By("expecting denial of CREATE API with invalid timeoutInSeconds")
281
+
varerr=hubClient.Create(ctx, profile)
282
+
Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
283
+
Expect(statusErr.Status().Message).Should(ContainSubstring("spec.monitorConfig.timeoutInSeconds in body should be less than or equal to 10"))
284
+
Expect(statusErr.Status().Message).Should(ContainSubstring("timeoutInSeconds must be between 5 and 10 when intervalInSeconds is 30"))
285
+
})
182
286
})
183
287
184
288
Context("Test TrafficManagerProfile API validation - valid cases", func() {
@@ -231,6 +335,138 @@ var _ = Describe("Test networking v1alpha1 API validation", func() {
231
335
Expect(hubClient.Create(ctx, trafficManagerProfileName)).Should(Succeed(), "failed to create trafficManagerProfile")
232
336
Expect(hubClient.Delete(ctx, trafficManagerProfileName)).Should(Succeed(), "failed to delete trafficManagerProfile")
233
337
})
338
+
339
+
It("should allow creating API with valid timeoutInSeconds when intervalInSeconds is 30", func() {
340
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
341
+
ObjectMeta: objectMetaWithNameValid,
342
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
343
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
344
+
IntervalInSeconds: ptr.To(int64(30)),
345
+
TimeoutInSeconds: ptr.To(int64(7)),
346
+
},
347
+
ResourceGroup: "test-resource-group",
348
+
},
349
+
}
350
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile")
351
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile")
352
+
})
353
+
354
+
It("should allow creating API with timeoutInSeconds at lower bound (5) when intervalInSeconds is 30", func() {
355
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
356
+
ObjectMeta: objectMetaWithNameValid,
357
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
358
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
359
+
IntervalInSeconds: ptr.To(int64(30)),
360
+
TimeoutInSeconds: ptr.To(int64(5)),
361
+
},
362
+
ResourceGroup: "test-resource-group",
363
+
},
364
+
}
365
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile at lower bound")
366
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile at lower bound")
367
+
})
368
+
369
+
It("should allow creating API with timeoutInSeconds at upper bound (10) when intervalInSeconds is 30", func() {
370
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
371
+
ObjectMeta: objectMetaWithNameValid,
372
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
373
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
374
+
IntervalInSeconds: ptr.To(int64(30)),
375
+
TimeoutInSeconds: ptr.To(int64(10)),
376
+
},
377
+
ResourceGroup: "test-resource-group",
378
+
},
379
+
}
380
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile at upper bound")
381
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile at upper bound")
382
+
})
383
+
384
+
It("should allow creating API with valid timeoutInSeconds when intervalInSeconds is 10", func() {
385
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
386
+
ObjectMeta: objectMetaWithNameValid,
387
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
388
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
389
+
IntervalInSeconds: ptr.To(int64(10)),
390
+
TimeoutInSeconds: ptr.To(int64(8)),
391
+
},
392
+
ResourceGroup: "test-resource-group",
393
+
},
394
+
}
395
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile")
396
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile")
397
+
})
398
+
399
+
It("should allow creating API with timeoutInSeconds at lower bound (5) when intervalInSeconds is 10", func() {
400
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
401
+
ObjectMeta: objectMetaWithNameValid,
402
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
403
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
404
+
IntervalInSeconds: ptr.To(int64(10)),
405
+
TimeoutInSeconds: ptr.To(int64(5)),
406
+
},
407
+
ResourceGroup: "test-resource-group",
408
+
},
409
+
}
410
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile at lower bound")
411
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile at lower bound")
412
+
})
413
+
414
+
It("should allow creating API with timeoutInSeconds at upper bound (9) when intervalInSeconds is 10", func() {
415
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
416
+
ObjectMeta: objectMetaWithNameValid,
417
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
418
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
419
+
IntervalInSeconds: ptr.To(int64(30)),
420
+
TimeoutInSeconds: ptr.To(int64(9)),
421
+
},
422
+
ResourceGroup: "test-resource-group",
423
+
},
424
+
}
425
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile at upper bound")
426
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile at upper bound")
427
+
})
428
+
429
+
It("should allow creating API with valid timeoutInSeconds when intervalInSeconds is not defined", func() {
430
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
431
+
ObjectMeta: objectMetaWithNameValid,
432
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
433
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
434
+
TimeoutInSeconds: ptr.To(int64(10)),
435
+
},
436
+
ResourceGroup: "test-resource-group",
437
+
},
438
+
}
439
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile")
440
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile")
441
+
})
442
+
443
+
It("should allow creating API with timeoutInSeconds at lower bound (5) when intervalInSeconds is not defined", func() {
444
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
445
+
ObjectMeta: objectMetaWithNameValid,
446
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
447
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
448
+
TimeoutInSeconds: ptr.To(int64(5)),
449
+
},
450
+
ResourceGroup: "test-resource-group",
451
+
},
452
+
}
453
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile at lower bound")
454
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile at lower bound")
455
+
})
456
+
457
+
It("should allow creating API with timeoutInSeconds at upper bound (10) when intervalInSeconds is not defined", func() {
458
+
profile:=&fleetnetv1beta1.TrafficManagerProfile{
459
+
ObjectMeta: objectMetaWithNameValid,
460
+
Spec: fleetnetv1beta1.TrafficManagerProfileSpec{
461
+
MonitorConfig: &fleetnetv1beta1.MonitorConfig{
462
+
TimeoutInSeconds: ptr.To(int64(10)),
463
+
},
464
+
ResourceGroup: "test-resource-group",
465
+
},
466
+
}
467
+
Expect(hubClient.Create(ctx, profile)).Should(Succeed(), "failed to create trafficManagerProfile at upper bound")
468
+
Expect(hubClient.Delete(ctx, profile)).Should(Succeed(), "failed to delete trafficManagerProfile at upper bound")
469
+
})
234
470
})
235
471
236
472
Context("Test TrafficManagerBackend API validation - invalid cases", func() {
0 commit comments