Skip to content

Commit 8462f54

Browse files
lmicciniclaude
andcommitted
Migrate terminationGracePeriodSeconds from 604800 to 60 in webhook
The upstream rabbitmq-cluster-operator defaults to 604800s (7 days) for terminationGracePeriodSeconds. Combined with containers that do not handle SIGTERM properly, this causes pods to stay in Terminating state for days. Add a defaulting webhook that sets the value to 60s for existing clusters still carrying the old default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b855d67 commit 8462f54

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

apis/rabbitmq/v1beta1/rabbitmq_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ func (spec *RabbitMqSpecCore) Default(isNew bool) {
140140
spec.QueueType = &queueType
141141
}
142142

143+
// Migrate terminationGracePeriodSeconds from old default (604800) to new (60).
144+
// The old value was inherited from rabbitmq-cluster-operator and causes pods
145+
// to get stuck in Terminating state for up to a week.
146+
oldGracePeriod := int64(604800)
147+
newGracePeriod := int64(60)
148+
if spec.TerminationGracePeriodSeconds != nil && *spec.TerminationGracePeriodSeconds == oldGracePeriod {
149+
spec.TerminationGracePeriodSeconds = &newGracePeriod
150+
rabbitmqlog.Info("Migrating terminationGracePeriodSeconds from old default 604800 to 60")
151+
}
152+
143153
// Force Mirrored → Quorum when upgrading to RabbitMQ 4.x+.
144154
// Mirrored queues are not supported in 4.x, so the migration is mandatory.
145155
if spec.QueueType != nil && *spec.QueueType == QueueTypeMirrored &&
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import "testing"
20+
21+
func TestSpecCoreDefault_MigratesOldGracePeriod(t *testing.T) {
22+
oldDefault := int64(604800)
23+
spec := RabbitMqSpecCore{
24+
TerminationGracePeriodSeconds: &oldDefault,
25+
}
26+
27+
spec.Default(false)
28+
29+
if spec.TerminationGracePeriodSeconds == nil {
30+
t.Fatal("TerminationGracePeriodSeconds should not be nil")
31+
}
32+
if *spec.TerminationGracePeriodSeconds != 60 {
33+
t.Errorf("TerminationGracePeriodSeconds = %d, want 60", *spec.TerminationGracePeriodSeconds)
34+
}
35+
}
36+
37+
func TestSpecCoreDefault_PreservesCustomGracePeriod(t *testing.T) {
38+
custom := int64(120)
39+
spec := RabbitMqSpecCore{
40+
TerminationGracePeriodSeconds: &custom,
41+
}
42+
43+
spec.Default(false)
44+
45+
if spec.TerminationGracePeriodSeconds == nil {
46+
t.Fatal("TerminationGracePeriodSeconds should not be nil")
47+
}
48+
if *spec.TerminationGracePeriodSeconds != 120 {
49+
t.Errorf("TerminationGracePeriodSeconds = %d, want 120", *spec.TerminationGracePeriodSeconds)
50+
}
51+
}
52+
53+
func TestSpecCoreDefault_PreservesNewDefault(t *testing.T) {
54+
newDefault := int64(60)
55+
spec := RabbitMqSpecCore{
56+
TerminationGracePeriodSeconds: &newDefault,
57+
}
58+
59+
spec.Default(false)
60+
61+
if spec.TerminationGracePeriodSeconds == nil {
62+
t.Fatal("TerminationGracePeriodSeconds should not be nil")
63+
}
64+
if *spec.TerminationGracePeriodSeconds != 60 {
65+
t.Errorf("TerminationGracePeriodSeconds = %d, want 60", *spec.TerminationGracePeriodSeconds)
66+
}
67+
}

0 commit comments

Comments
 (0)