|
39 | 39 | Scheme: ptr.To("HTTPS"), |
40 | 40 | StaticConfigs: []promv1alpha1.StaticConfig{ |
41 | 41 | { |
42 | | - |
43 | 42 | Targets: []promv1alpha1.Target{ |
44 | 43 | "localhost:9100", |
45 | 44 | }, |
|
61 | 60 | return nil |
62 | 61 | }, |
63 | 62 | }, |
64 | | - |
65 | 63 | { |
66 | 64 | name: "PrometheusScrapeConfig", |
67 | 65 | source: &promv1alpha1.ScrapeConfig{ |
@@ -297,106 +295,98 @@ func getObject(ctx context.Context, obj client.Object) (client.Object, error) { |
297 | 295 | return obj, err |
298 | 296 | } |
299 | 297 |
|
300 | | -var _ = Describe("test prometheusConverter Controller", func() { |
301 | | - Context("e2e prome converter", func() { |
302 | | - for _, testCaseIt := range testCases { |
303 | | - testCase := testCaseIt |
| 298 | +var _ = Describe("prometheus converter", Label("vm", "prom"), func() { |
| 299 | + for _, tc := range testCases { |
| 300 | + Context(fmt.Sprintf("crud %s", tc.name), func() { |
304 | 301 | // adapt test for parallel execution |
305 | 302 | // https://onsi.github.io/ginkgo/#patterns-for-parallel-integration-specs |
306 | 303 | procSuffix := fmt.Sprintf("-%d", GinkgoParallelProcess()) |
307 | | - testCase.source.SetName(testCase.source.GetName() + procSuffix) |
308 | | - testCase.targetTpl.SetName(testCase.targetTpl.GetName() + procSuffix) |
| 304 | + tc.source.SetName(tc.source.GetName() + procSuffix) |
| 305 | + tc.targetTpl.SetName(tc.targetTpl.GetName() + procSuffix) |
309 | 306 | ctx := context.Background() |
310 | | - Context(fmt.Sprintf("crud %s", testCase.name), func() { |
311 | | - AfterEach(func() { |
312 | | - k8sClient.Delete(ctx, testCase.source) // nolint:errcheck |
313 | | - Eventually(func() error { |
314 | | - _, err := getObject(ctx, testCase.source) |
| 307 | + AfterEach(func() { |
| 308 | + k8sClient.Delete(ctx, tc.source) // nolint:errcheck |
| 309 | + Eventually(func() error { |
| 310 | + _, err := getObject(ctx, tc.source) |
| 311 | + return err |
| 312 | + }, eventualDeletionTimeout, 1).Should(MatchError(k8serrors.IsNotFound, "IsNotFound")) |
| 313 | + k8sClient.Delete(ctx, tc.targetTpl) // nolint:errcheck |
| 314 | + Eventually(func() error { |
| 315 | + _, err := getObject(ctx, tc.targetTpl) |
| 316 | + if err == nil { |
| 317 | + return fmt.Errorf("Should be deleted") |
| 318 | + } |
| 319 | + return nil |
| 320 | + }, 60, 1).Should(Succeed()) |
| 321 | + }) |
| 322 | + It("Should convert the object", func() { |
| 323 | + source := tc.source.DeepCopyObject().(client.Object) |
| 324 | + Expect(k8sClient.Create(ctx, source)).To(Succeed()) |
| 325 | + Eventually(func() error { |
| 326 | + target, err := getObject(ctx, tc.targetTpl) |
| 327 | + if err != nil { |
315 | 328 | return err |
316 | | - }, eventualDeletionTimeout, 1).Should(MatchError(k8serrors.IsNotFound, "IsNotFound")) |
317 | | - |
318 | | - k8sClient.Delete(ctx, testCase.targetTpl) // nolint:errcheck |
319 | | - Eventually(func() error { |
320 | | - _, err := getObject(ctx, testCase.targetTpl) |
321 | | - if err == nil { |
322 | | - return fmt.Errorf("Should be deleted") |
323 | | - } |
324 | | - return nil |
325 | | - }, 60, 1).Should(Succeed()) |
326 | | - }) |
327 | | - |
328 | | - It("Should convert the object", func() { |
329 | | - source := testCase.source.DeepCopyObject().(client.Object) |
| 329 | + } |
| 330 | + return tc.targetValidator(target) |
| 331 | + }, 60, 1).Should(Succeed()) |
| 332 | + }) |
330 | 333 |
|
331 | | - Expect(k8sClient.Create(ctx, source)).To(Succeed()) |
332 | | - Eventually(func() error { |
333 | | - target, err := getObject(ctx, testCase.targetTpl) |
334 | | - if err != nil { |
335 | | - return err |
336 | | - } |
337 | | - return testCase.targetValidator(target) |
338 | | - }, 60, 1).Should(Succeed()) |
339 | | - }) |
| 334 | + It("Should update the converted object", func() { |
| 335 | + source := tc.source.DeepCopyObject().(client.Object) |
| 336 | + Expect(k8sClient.Create(ctx, source)).To(Succeed()) |
| 337 | + Eventually(func() error { |
| 338 | + _, err := getObject(ctx, tc.targetTpl) |
| 339 | + return err |
| 340 | + }, 60, 1).Should(Succeed()) |
340 | 341 |
|
341 | | - It("Should update the converted object", func() { |
342 | | - source := testCase.source.DeepCopyObject().(client.Object) |
| 342 | + labels := source.GetLabels() |
| 343 | + if labels == nil { |
| 344 | + labels = make(map[string]string) |
| 345 | + } |
| 346 | + // Use this hack to trigger update manually for GenerationChange predicate |
| 347 | + // It's not a problem for production workloads |
| 348 | + // Since operator performs period syncs for parent objects |
| 349 | + source.SetGeneration(source.GetGeneration() + 1) |
| 350 | + labels["testKey"] = "testValue" |
| 351 | + source.SetLabels(labels) |
343 | 352 |
|
344 | | - Expect(k8sClient.Create(ctx, source)).To(Succeed()) |
345 | | - Eventually(func() error { |
346 | | - _, err := getObject(ctx, testCase.targetTpl) |
| 353 | + Expect(k8sClient.Update(ctx, source)).To(Succeed()) |
| 354 | + Eventually(func() error { |
| 355 | + target, err := getObject(ctx, tc.targetTpl) |
| 356 | + if err != nil { |
347 | 357 | return err |
348 | | - }, 60, 1).Should(Succeed()) |
349 | | - |
350 | | - labels := source.GetLabels() |
351 | | - if labels == nil { |
352 | | - labels = make(map[string]string) |
353 | 358 | } |
354 | | - // Use this hack to trigger update manually for GenerationChange predicate |
355 | | - // It's not a problem for production workloads |
356 | | - // Since operator performs period syncs for parent objects |
357 | | - source.SetGeneration(source.GetGeneration() + 1) |
358 | | - labels["testKey"] = "testValue" |
359 | | - source.SetLabels(labels) |
360 | | - |
361 | | - Expect(k8sClient.Update(ctx, source)).To(Succeed()) |
362 | | - Eventually(func() error { |
363 | | - target, err := getObject(ctx, testCase.targetTpl) |
364 | | - if err != nil { |
365 | | - return err |
366 | | - } |
367 | | - if target.GetLabels() == nil || target.GetLabels()["testKey"] != "testValue" { |
368 | | - return fmt.Errorf("unexpected labels, want testKey=testValue, got: %v", target.GetLabels()) |
369 | | - } |
370 | | - return nil |
371 | | - }, 60, 1).Should(Succeed()) |
372 | | - }) |
| 359 | + if target.GetLabels() == nil || target.GetLabels()["testKey"] != "testValue" { |
| 360 | + return fmt.Errorf("unexpected labels, want testKey=testValue, got: %v", target.GetLabels()) |
| 361 | + } |
| 362 | + return nil |
| 363 | + }, 60, 1).Should(Succeed()) |
| 364 | + }) |
373 | 365 |
|
374 | | - It("Should delete the converted object", func() { |
375 | | - source := testCase.source.DeepCopyObject().(client.Object) |
| 366 | + It("Should delete the converted object", func() { |
| 367 | + source := tc.source.DeepCopyObject().(client.Object) |
| 368 | + Expect(k8sClient.Create(ctx, source)).To(Succeed()) |
| 369 | + Eventually(func() error { |
| 370 | + _, err := getObject(ctx, tc.targetTpl) |
| 371 | + return err |
| 372 | + }, 60, 1).Should(Succeed()) |
376 | 373 |
|
377 | | - Expect(k8sClient.Create(ctx, source)).To(Succeed()) |
378 | | - Eventually(func() error { |
379 | | - _, err := getObject(ctx, testCase.targetTpl) |
| 374 | + Expect(func() error { |
| 375 | + target, err := getObject(ctx, tc.targetTpl) |
| 376 | + if err != nil { |
380 | 377 | return err |
381 | | - }, 60, 1).Should(Succeed()) |
382 | | - |
383 | | - Expect(func() error { |
384 | | - target, err := getObject(ctx, testCase.targetTpl) |
385 | | - if err != nil { |
386 | | - return err |
387 | | - } |
388 | | - if target.GetOwnerReferences() == nil { |
389 | | - return fmt.Errorf("expected owner reference to be non nil, object :%s", target.GetName()) |
390 | | - } |
391 | | - return nil |
392 | | - }()).To(Succeed()) |
393 | | - Expect(k8sClient.Delete(ctx, source)).To(Succeed()) |
394 | | - Eventually(func() error { |
395 | | - _, err := getObject(ctx, testCase.targetTpl) |
396 | | - return err |
397 | | - }, eventualDeletionTimeout, 1).Should(MatchError(k8serrors.IsNotFound, "IsNotFound")) |
398 | | - }) |
| 378 | + } |
| 379 | + if target.GetOwnerReferences() == nil { |
| 380 | + return fmt.Errorf("expected owner reference to be non nil, object: %s", target.GetName()) |
| 381 | + } |
| 382 | + return nil |
| 383 | + }()).To(Succeed()) |
| 384 | + Expect(k8sClient.Delete(ctx, source)).To(Succeed()) |
| 385 | + Eventually(func() error { |
| 386 | + _, err := getObject(ctx, tc.targetTpl) |
| 387 | + return err |
| 388 | + }, eventualDeletionTimeout, 1).Should(MatchError(k8serrors.IsNotFound, "IsNotFound")) |
399 | 389 | }) |
400 | | - } |
401 | | - }) |
| 390 | + }) |
| 391 | + } |
402 | 392 | }) |
0 commit comments