Skip to content

Commit b239aef

Browse files
committed
Make TerminationGracePeriodSeconds configurable
- related to issue #419
1 parent 7b4de78 commit b239aef

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

api/v1beta1/rabbitmqcluster_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ type RabbitmqClusterSpec struct {
6363
// Has no effect if the cluster only consists of one node.
6464
// For more information, see https://www.rabbitmq.com/rabbitmq-queues.8.html#rebalance
6565
SkipPostDeploySteps bool `json:"skipPostDeploySteps,omitempty"`
66+
// TerminationGracePeriodSeconds is the timeout that each rabbitmqcluster pod will have to terminate gracefully
67+
// It defaults to 604800 seconds ( a week long) to ensure that the container preStop lifecycle hook can finish running
68+
// For more information, see: https://github.com/rabbitmq/cluster-operator/blob/main/docs/design/20200520-graceful-pod-termination.md
69+
// +kubebuilder:validation:Minimum:=0
70+
// +kubebuilder:default:=604800
71+
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
6672
}
6773

6874
type RabbitmqClusterOverrideSpec struct {

api/v1beta1/rabbitmqcluster_types_test.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ var _ = Describe("RabbitmqCluster", func() {
179179

180180
When("CR is fully populated", func() {
181181
It("outputs the CR", func() {
182+
zero := int64(0)
182183
storage := k8sresource.MustParse("987Gi")
183184
storageClassName := "some-class"
184185
rmqClusterInstance = RabbitmqCluster{
@@ -187,9 +188,10 @@ var _ = Describe("RabbitmqCluster", func() {
187188
Namespace: "default",
188189
},
189190
Spec: RabbitmqClusterSpec{
190-
Replicas: &three,
191-
Image: "rabbitmq-image-from-cr",
192-
ImagePullSecrets: []corev1.LocalObjectReference{{Name: "my-super-secret"}},
191+
Replicas: &three,
192+
Image: "rabbitmq-image-from-cr",
193+
ImagePullSecrets: []corev1.LocalObjectReference{{Name: "my-super-secret"}},
194+
TerminationGracePeriodSeconds: &zero,
193195
Service: RabbitmqClusterServiceSpec{
194196
Type: "NodePort",
195197
Annotations: map[string]string{
@@ -470,14 +472,16 @@ func getKey(cluster *RabbitmqCluster) types.NamespacedName {
470472

471473
func generateRabbitmqClusterObject(clusterName string) *RabbitmqCluster {
472474
storage := k8sresource.MustParse("10Gi")
475+
terminationPeriod := int64(604800)
473476
return &RabbitmqCluster{
474477
ObjectMeta: metav1.ObjectMeta{
475478
Name: clusterName,
476479
Namespace: "default",
477480
},
478481
Spec: RabbitmqClusterSpec{
479-
Replicas: pointer.Int32Ptr(1),
480-
Image: "rabbitmq:3.8.9",
482+
Replicas: pointer.Int32Ptr(1),
483+
Image: "rabbitmq:3.8.9",
484+
TerminationGracePeriodSeconds: &terminationPeriod,
481485
Service: RabbitmqClusterServiceSpec{
482486
Type: "ClusterIP",
483487
},

api/v1beta1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,15 @@ spec:
37233723
the cluster only consists of one node. For more information, see
37243724
https://www.rabbitmq.com/rabbitmq-queues.8.html#rebalance
37253725
type: boolean
3726+
terminationGracePeriodSeconds:
3727+
default: 604800
3728+
description: 'TerminationGracePeriodSeconds is the timeout that each
3729+
rabbitmqcluster pod will have to terminate gracefully It defaults
3730+
to 604800 seconds ( a week long) to ensure that the container preStop
3731+
lifecycle hook can finish running For more information, see: https://github.com/rabbitmq/cluster-operator/blob/main/docs/design/20200520-graceful-pod-termination.md'
3732+
format: int64
3733+
minimum: 0
3734+
type: integer
37263735
tls:
37273736
properties:
37283737
caCertName:

internal/resource/statefulset.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ func (builder *StatefulSetBuilder) podTemplateSpec(annotations, labels map[strin
245245
rabbitmqGID := int64(999)
246246
rabbitmqUID := int64(999)
247247

248-
terminationGracePeriod := defaultGracePeriodTimeoutSeconds
249-
250248
volumes := []corev1.Volume{
251249
{
252250
Name: "server-conf",
@@ -510,7 +508,7 @@ func (builder *StatefulSetBuilder) podTemplateSpec(annotations, labels map[strin
510508
RunAsUser: &rabbitmqUID,
511509
},
512510
ImagePullSecrets: builder.Instance.Spec.ImagePullSecrets,
513-
TerminationGracePeriodSeconds: &terminationGracePeriod,
511+
TerminationGracePeriodSeconds: builder.Instance.Spec.TerminationGracePeriodSeconds,
514512
ServiceAccountName: builder.Instance.ChildResourceName(serviceAccountName),
515513
AutomountServiceAccountToken: &automountServiceAccountToken,
516514
Affinity: builder.Instance.Spec.Affinity,

internal/resource/statefulset_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -1011,12 +1011,19 @@ var _ = Describe("StatefulSet", func() {
10111011
}))
10121012
})
10131013

1014-
It("adds the required terminationGracePeriodSeconds", func() {
1014+
It("sets TerminationGracePeriodSeconds in podTemplate as provided in instance spec", func() {
1015+
ten := int64(10)
1016+
instance.Spec.TerminationGracePeriodSeconds = &ten
1017+
builder = &resource.RabbitmqResourceBuilder{
1018+
Instance: &instance,
1019+
Scheme: scheme,
1020+
}
1021+
10151022
stsBuilder := builder.StatefulSet()
10161023
Expect(stsBuilder.Update(statefulSet)).To(Succeed())
10171024

10181025
gracePeriodSeconds := statefulSet.Spec.Template.Spec.TerminationGracePeriodSeconds
1019-
expectedGracePeriodSeconds := int64(60 * 60 * 24 * 7)
1026+
expectedGracePeriodSeconds := int64(10)
10201027
Expect(gracePeriodSeconds).To(Equal(&expectedGracePeriodSeconds))
10211028
})
10221029

0 commit comments

Comments
 (0)