|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2020, Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. |
3 | 3 | * Licensed under the Universal Permissive License v 1.0 as shown at
|
4 | 4 | * http://oss.oracle.com/licenses/upl.
|
5 | 5 | */
|
@@ -380,3 +380,204 @@ func TestCreateStatefulSetWithLivenessProbeSpecWithExec(t *testing.T) {
|
380 | 380 | // assert that the StatefulSet is as expected
|
381 | 381 | assertStatefulSetCreation(t, deployment, stsExpected)
|
382 | 382 | }
|
| 383 | + |
| 384 | +func TestCreateStatefulSetWithNilStartupProbeSpec(t *testing.T) { |
| 385 | + |
| 386 | + spec := coh.CoherenceResourceSpec{ |
| 387 | + StartupProbe: nil, |
| 388 | + } |
| 389 | + |
| 390 | + // Create the test deployment |
| 391 | + deployment := createTestDeployment(spec) |
| 392 | + |
| 393 | + // Create expected StatefulSet |
| 394 | + stsExpected := createMinimalExpectedStatefulSet(deployment) |
| 395 | + |
| 396 | + // assert that the StatefulSet is as expected |
| 397 | + assertStatefulSetCreation(t, deployment, stsExpected) |
| 398 | +} |
| 399 | + |
| 400 | +func TestCreateStatefulSetWithEmptyStartupProbeSpec(t *testing.T) { |
| 401 | + |
| 402 | + probe := coh.ReadinessProbeSpec{} |
| 403 | + |
| 404 | + spec := coh.CoherenceResourceSpec{ |
| 405 | + StartupProbe: &probe, |
| 406 | + } |
| 407 | + |
| 408 | + // Create the test deployment |
| 409 | + deployment := createTestDeployment(spec) |
| 410 | + |
| 411 | + // Create expected probe |
| 412 | + probeExpected := spec.UpdateDefaultLivenessProbeAction(spec.CreateDefaultLivenessProbe()) |
| 413 | + |
| 414 | + // Create expected StatefulSet |
| 415 | + stsExpected := createMinimalExpectedStatefulSet(deployment) |
| 416 | + stsExpected.Spec.Template.Spec.Containers[0].StartupProbe = probeExpected |
| 417 | + |
| 418 | + // assert that the StatefulSet is as expected |
| 419 | + assertStatefulSetCreation(t, deployment, stsExpected) |
| 420 | +} |
| 421 | + |
| 422 | +func TestCreateStatefulSetWithStartupProbeSpec(t *testing.T) { |
| 423 | + |
| 424 | + probe := coh.ReadinessProbeSpec{ |
| 425 | + InitialDelaySeconds: int32Ptr(10), |
| 426 | + TimeoutSeconds: int32Ptr(20), |
| 427 | + PeriodSeconds: int32Ptr(30), |
| 428 | + SuccessThreshold: int32Ptr(40), |
| 429 | + FailureThreshold: int32Ptr(50), |
| 430 | + } |
| 431 | + |
| 432 | + spec := coh.CoherenceResourceSpec{ |
| 433 | + StartupProbe: &probe, |
| 434 | + } |
| 435 | + |
| 436 | + // Create the test deployment |
| 437 | + deployment := createTestDeployment(spec) |
| 438 | + // Create expected StatefulSet |
| 439 | + stsExpected := createMinimalExpectedStatefulSet(deployment) |
| 440 | + stsExpected.Spec.Template.Spec.Containers[0].StartupProbe = &corev1.Probe{ |
| 441 | + Handler: corev1.Handler{ |
| 442 | + Exec: nil, |
| 443 | + HTTPGet: &corev1.HTTPGetAction{ |
| 444 | + Path: coh.DefaultLivenessPath, |
| 445 | + Port: intstr.FromInt(int(coh.DefaultHealthPort)), |
| 446 | + Scheme: "HTTP", |
| 447 | + }, |
| 448 | + TCPSocket: nil, |
| 449 | + }, |
| 450 | + InitialDelaySeconds: 10, |
| 451 | + TimeoutSeconds: 20, |
| 452 | + PeriodSeconds: 30, |
| 453 | + SuccessThreshold: 40, |
| 454 | + FailureThreshold: 50, |
| 455 | + } |
| 456 | + |
| 457 | + // assert that the StatefulSet is as expected |
| 458 | + assertStatefulSetCreation(t, deployment, stsExpected) |
| 459 | +} |
| 460 | + |
| 461 | +func TestCreateStatefulSetWithStartupProbeSpecWithHttpGet(t *testing.T) { |
| 462 | + |
| 463 | + handler := &corev1.HTTPGetAction{ |
| 464 | + Path: "/test/ready", |
| 465 | + Port: intstr.FromInt(1234), |
| 466 | + } |
| 467 | + |
| 468 | + probe := coh.ReadinessProbeSpec{ |
| 469 | + ProbeHandler: coh.ProbeHandler{ |
| 470 | + Exec: nil, |
| 471 | + HTTPGet: handler, |
| 472 | + TCPSocket: nil, |
| 473 | + }, |
| 474 | + InitialDelaySeconds: int32Ptr(10), |
| 475 | + TimeoutSeconds: int32Ptr(20), |
| 476 | + PeriodSeconds: int32Ptr(30), |
| 477 | + SuccessThreshold: int32Ptr(40), |
| 478 | + FailureThreshold: int32Ptr(50), |
| 479 | + } |
| 480 | + |
| 481 | + spec := coh.CoherenceResourceSpec{ |
| 482 | + StartupProbe: &probe, |
| 483 | + } |
| 484 | + |
| 485 | + // Create the test deployment |
| 486 | + deployment := createTestDeployment(spec) |
| 487 | + // Create expected StatefulSet |
| 488 | + stsExpected := createMinimalExpectedStatefulSet(deployment) |
| 489 | + stsExpected.Spec.Template.Spec.Containers[0].StartupProbe = &corev1.Probe{ |
| 490 | + Handler: corev1.Handler{ |
| 491 | + HTTPGet: handler, |
| 492 | + }, |
| 493 | + InitialDelaySeconds: 10, |
| 494 | + TimeoutSeconds: 20, |
| 495 | + PeriodSeconds: 30, |
| 496 | + SuccessThreshold: 40, |
| 497 | + FailureThreshold: 50, |
| 498 | + } |
| 499 | + |
| 500 | + // assert that the StatefulSet is as expected |
| 501 | + assertStatefulSetCreation(t, deployment, stsExpected) |
| 502 | +} |
| 503 | + |
| 504 | +func TestCreateStatefulSetWithStartupProbeSpecWithTCPSocket(t *testing.T) { |
| 505 | + |
| 506 | + handler := &corev1.TCPSocketAction{ |
| 507 | + Port: intstr.FromInt(1234), |
| 508 | + Host: "foo.com", |
| 509 | + } |
| 510 | + |
| 511 | + probe := coh.ReadinessProbeSpec{ |
| 512 | + ProbeHandler: coh.ProbeHandler{ |
| 513 | + TCPSocket: handler, |
| 514 | + }, |
| 515 | + InitialDelaySeconds: int32Ptr(10), |
| 516 | + TimeoutSeconds: int32Ptr(20), |
| 517 | + PeriodSeconds: int32Ptr(30), |
| 518 | + SuccessThreshold: int32Ptr(40), |
| 519 | + FailureThreshold: int32Ptr(50), |
| 520 | + } |
| 521 | + |
| 522 | + spec := coh.CoherenceResourceSpec{ |
| 523 | + StartupProbe: &probe, |
| 524 | + } |
| 525 | + |
| 526 | + // Create the test deployment |
| 527 | + deployment := createTestDeployment(spec) |
| 528 | + // Create expected StatefulSet |
| 529 | + stsExpected := createMinimalExpectedStatefulSet(deployment) |
| 530 | + stsExpected.Spec.Template.Spec.Containers[0].StartupProbe = &corev1.Probe{ |
| 531 | + Handler: corev1.Handler{ |
| 532 | + TCPSocket: handler, |
| 533 | + }, |
| 534 | + InitialDelaySeconds: 10, |
| 535 | + TimeoutSeconds: 20, |
| 536 | + PeriodSeconds: 30, |
| 537 | + SuccessThreshold: 40, |
| 538 | + FailureThreshold: 50, |
| 539 | + } |
| 540 | + |
| 541 | + // assert that the StatefulSet is as expected |
| 542 | + assertStatefulSetCreation(t, deployment, stsExpected) |
| 543 | +} |
| 544 | + |
| 545 | +func TestCreateStatefulSetWithStartupProbeSpecWithExec(t *testing.T) { |
| 546 | + |
| 547 | + handler := &corev1.ExecAction{ |
| 548 | + Command: []string{"exec", "something"}, |
| 549 | + } |
| 550 | + |
| 551 | + probe := coh.ReadinessProbeSpec{ |
| 552 | + ProbeHandler: coh.ProbeHandler{ |
| 553 | + Exec: handler, |
| 554 | + }, |
| 555 | + InitialDelaySeconds: int32Ptr(10), |
| 556 | + TimeoutSeconds: int32Ptr(20), |
| 557 | + PeriodSeconds: int32Ptr(30), |
| 558 | + SuccessThreshold: int32Ptr(40), |
| 559 | + FailureThreshold: int32Ptr(50), |
| 560 | + } |
| 561 | + |
| 562 | + spec := coh.CoherenceResourceSpec{ |
| 563 | + StartupProbe: &probe, |
| 564 | + } |
| 565 | + |
| 566 | + // Create the test deployment |
| 567 | + deployment := createTestDeployment(spec) |
| 568 | + // Create expected StatefulSet |
| 569 | + stsExpected := createMinimalExpectedStatefulSet(deployment) |
| 570 | + stsExpected.Spec.Template.Spec.Containers[0].StartupProbe = &corev1.Probe{ |
| 571 | + Handler: corev1.Handler{ |
| 572 | + Exec: handler, |
| 573 | + }, |
| 574 | + InitialDelaySeconds: 10, |
| 575 | + TimeoutSeconds: 20, |
| 576 | + PeriodSeconds: 30, |
| 577 | + SuccessThreshold: 40, |
| 578 | + FailureThreshold: 50, |
| 579 | + } |
| 580 | + |
| 581 | + // assert that the StatefulSet is as expected |
| 582 | + assertStatefulSetCreation(t, deployment, stsExpected) |
| 583 | +} |
0 commit comments