Skip to content

Commit ee3efb5

Browse files
authored
Merge pull request #505 from vasac/startup-probes
Add support for Startup Probes
2 parents ba0f8ee + 944a53b commit ee3efb5

File tree

5 files changed

+350
-1
lines changed

5 files changed

+350
-1
lines changed

api/v1/coherenceresourcespec_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,14 @@ type CoherenceResourceSpec struct {
184184
// ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
185185
// +optional
186186
LivenessProbe *ReadinessProbeSpec `json:"livenessProbe,omitempty"`
187+
// The startup probe config to be used for the Pods in this deployment.
188+
// See: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
189+
// +optional
190+
StartupProbe *ReadinessProbeSpec `json:"startupProbe,omitempty"`
191+
// ReadinessGates defines a list of additional conditions that the kubelet evaluates for Pod readiness.
192+
// See: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-readiness-gate
193+
// +optional
194+
ReadinessGates []corev1.PodReadinessGate `json:"readinessGates,omitempty"`
187195
// Resources is the optional resource requests and limits for the containers
188196
// ref: http://kubernetes.io/docs/user-guide/compute-resources/
189197
//
@@ -664,6 +672,7 @@ func (in *CoherenceResourceSpec) CreateStatefulSet(deployment *Coherence) Resour
664672
Tolerations: in.Tolerations,
665673
Affinity: in.EnsurePodAffinity(deployment),
666674
NodeSelector: in.NodeSelector,
675+
ReadinessGates: in.ReadinessGates,
667676
InitContainers: []corev1.Container{
668677
in.CreateUtilsContainer(deployment),
669678
},
@@ -783,6 +792,11 @@ func (in *CoherenceResourceSpec) CreateCoherenceContainer(deployment *Coherence)
783792
c.LivenessProbe = in.CreateDefaultLivenessProbe()
784793
in.LivenessProbe.UpdateProbeSpec(healthPort, DefaultLivenessPath, c.LivenessProbe)
785794

795+
if in.StartupProbe != nil {
796+
c.StartupProbe = in.CreateDefaultLivenessProbe()
797+
in.StartupProbe.UpdateProbeSpec(healthPort, DefaultLivenessPath, c.StartupProbe)
798+
}
799+
786800
return c
787801
}
788802

api/v1/create_statefulset_probes_test.go

Lines changed: 202 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/
@@ -380,3 +380,204 @@ func TestCreateStatefulSetWithLivenessProbeSpecWithExec(t *testing.T) {
380380
// assert that the StatefulSet is as expected
381381
assertStatefulSetCreation(t, deployment, stsExpected)
382382
}
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+
}

api/v1/zz_generated.deepcopy.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)