Skip to content

Commit e164689

Browse files
authored
Expose additional StatefulSet and readiness probe fields (#742)
Add support for configuring minReadySeconds on a Coherence StatefulSet Add support for configuring terminationGracePeriodSeconds in readiness probes
1 parent 7526b67 commit e164689

File tree

5 files changed

+73
-11
lines changed

5 files changed

+73
-11
lines changed

api/v1/coherence_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,19 @@ type ReadinessProbeSpec struct {
23202320
// Minimum consecutive failures for the probe to be considered failed after having succeeded.
23212321
// +optional
23222322
FailureThreshold *int32 `json:"failureThreshold,omitempty"`
2323+
// TerminationGracePeriodSeconds is the optional duration in seconds the pod needs to terminate gracefully
2324+
// upon probe failure.
2325+
// The grace period is the duration in seconds after the processes running in the pod are sent
2326+
// a termination signal and the time when the processes are forcibly halted with a kill signal.
2327+
// Set this value longer than the expected cleanup time for your process.
2328+
// If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this
2329+
// value overrides the value provided by the pod spec.
2330+
// Value must be non-negative integer. The value zero indicates stop immediately via
2331+
// the kill signal (no opportunity to shut down).
2332+
// This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate.
2333+
// The minimum value is 1. spec.terminationGracePeriodSeconds is used if unset.
2334+
// +optional
2335+
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
23232336
}
23242337

23252338
// ProbeHandler is the definition of a probe handler.
@@ -2371,6 +2384,7 @@ func (in *ReadinessProbeSpec) UpdateProbeSpec(port int32, path string, probe *co
23712384
if in.TimeoutSeconds != nil {
23722385
probe.TimeoutSeconds = *in.TimeoutSeconds
23732386
}
2387+
probe.TerminationGracePeriodSeconds = in.TerminationGracePeriodSeconds
23742388
}
23752389
}
23762390

api/v1/coherenceresource_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ func (in *CoherenceStatefulSetResourceSpec) CreateStatefulSet(deployment *Cohere
677677
sts.Labels[LabelComponent] = LabelComponentCoherenceStatefulSet
678678
sts.Spec = appsv1.StatefulSetSpec{
679679
Replicas: &replicas,
680+
MinReadySeconds: in.GetMinReadySeconds(),
680681
PodManagementPolicy: appsv1.ParallelPodManagement,
681682
UpdateStrategy: updateStrategy,
682683
RevisionHistoryLimit: ptr.To(int32(5)),

api/v1/coherenceresourcespec_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ type CoherenceResourceSpec struct {
290290
// Cannot be updated.
291291
// +optional
292292
Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"`
293+
// Minimum number of seconds for which a newly created pod should be ready
294+
// without any of its container crashing for it to be considered available.
295+
// Defaults to 0 (pod will be considered available as soon as it is ready)
296+
// +optional
297+
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
293298
}
294299

295300
// Action is an action to execute when the StatefulSet becomes ready.
@@ -399,6 +404,15 @@ func (in *CoherenceResourceSpec) GetDefaultScalingProbe() *Probe {
399404
return probe.DeepCopy()
400405
}
401406

407+
// GetMinReadySeconds returns the minReadySeconds value or zero if
408+
// minReadySeconds is not configured.
409+
func (in *CoherenceResourceSpec) GetMinReadySeconds() int32 {
410+
if in == nil || in.MinReadySeconds == nil {
411+
return 0
412+
}
413+
return *in.MinReadySeconds
414+
}
415+
402416
// GetCoherencePersistence returns the Coherence PersistenceSpec or nil if
403417
// persistence is not configured.
404418
func (in *CoherenceResourceSpec) GetCoherencePersistence() *PersistenceSpec {

api/v1/create_statefulset_probes_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2025, 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
*/
@@ -10,6 +10,7 @@ import (
1010
coh "github.com/oracle/coherence-operator/api/v1"
1111
corev1 "k8s.io/api/core/v1"
1212
"k8s.io/apimachinery/pkg/util/intstr"
13+
"k8s.io/utils/ptr"
1314
"testing"
1415
)
1516

@@ -37,11 +38,12 @@ func TestCreateStatefulSetWithEmptyReadinessProbeSpec(t *testing.T) {
3738
func TestCreateStatefulSetWithReadinessProbeSpec(t *testing.T) {
3839

3940
probe := coh.ReadinessProbeSpec{
40-
InitialDelaySeconds: int32Ptr(10),
41-
TimeoutSeconds: int32Ptr(20),
42-
PeriodSeconds: int32Ptr(30),
43-
SuccessThreshold: int32Ptr(40),
44-
FailureThreshold: int32Ptr(50),
41+
InitialDelaySeconds: int32Ptr(10),
42+
TimeoutSeconds: int32Ptr(20),
43+
PeriodSeconds: int32Ptr(30),
44+
SuccessThreshold: int32Ptr(40),
45+
FailureThreshold: int32Ptr(50),
46+
TerminationGracePeriodSeconds: ptr.To(int64(1234)),
4547
}
4648

4749
spec := coh.CoherenceResourceSpec{
@@ -62,11 +64,12 @@ func TestCreateStatefulSetWithReadinessProbeSpec(t *testing.T) {
6264
},
6365
TCPSocket: nil,
6466
},
65-
InitialDelaySeconds: 10,
66-
TimeoutSeconds: 20,
67-
PeriodSeconds: 30,
68-
SuccessThreshold: 40,
69-
FailureThreshold: 50,
67+
InitialDelaySeconds: 10,
68+
TimeoutSeconds: 20,
69+
PeriodSeconds: 30,
70+
SuccessThreshold: 40,
71+
FailureThreshold: 50,
72+
TerminationGracePeriodSeconds: ptr.To(int64(1234)),
7073
}
7174

7275
// assert that the StatefulSet is as expected

api/v1/create_statefulset_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,33 @@ func TestCreateStatefulUsingJava8(t *testing.T) {
797797
// assert that the StatefulSet is as expected
798798
assertStatefulSetCreation(t, deployment, stsExpected)
799799
}
800+
801+
func TestCreateStatefulSetWithMinReadySeconds(t *testing.T) {
802+
spec := coh.CoherenceResourceSpec{
803+
MinReadySeconds: ptr.To(int32(19)),
804+
}
805+
806+
// Create the test deployment
807+
deployment := createTestDeployment(spec)
808+
// Create expected StatefulSet
809+
stsExpected := createMinimalExpectedStatefulSet(deployment)
810+
stsExpected.Spec.MinReadySeconds = 19
811+
812+
// assert that the StatefulSet is as expected
813+
assertStatefulSetCreation(t, deployment, stsExpected)
814+
}
815+
816+
func TestCreateStatefulSetWithMinReadySecondsSetToZero(t *testing.T) {
817+
spec := coh.CoherenceResourceSpec{
818+
MinReadySeconds: ptr.To(int32(0)),
819+
}
820+
821+
// Create the test deployment
822+
deployment := createTestDeployment(spec)
823+
// Create expected StatefulSet
824+
stsExpected := createMinimalExpectedStatefulSet(deployment)
825+
stsExpected.Spec.MinReadySeconds = 0
826+
827+
// assert that the StatefulSet is as expected
828+
assertStatefulSetCreation(t, deployment, stsExpected)
829+
}

0 commit comments

Comments
 (0)