Skip to content

Commit

Permalink
Ignore mirroring related shutdown errors (#1740)
Browse files Browse the repository at this point in the history
RabbitMQ 4.0 doesn't include the mirroring-specific command `rabbitmq-upgrade await_online_synchronized_mirror`.
Therefore, the preStop hook would fail on 4.0, leading to the
maintenance mode not getting enabled at all (the moment a command fails
in preStop, the shutdown process continues as if preStop completed).

This approach should make the Operator compatible with 3.x and 4.x.
  • Loading branch information
mkuratczyk authored Oct 8, 2024
1 parent 6fc5fd4 commit aa72d5d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/resource/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (builder *StatefulSetBuilder) podTemplateSpec(previousPodAnnotations map[st
Command: []string{"/bin/bash", "-c",
fmt.Sprintf("if [ ! -z \"$(cat /etc/pod-info/%s)\" ]; then exit 0; fi;", DeletionMarker) +
fmt.Sprintf(" rabbitmq-upgrade await_online_quorum_plus_one -t %d &&"+
" rabbitmq-upgrade await_online_synchronized_mirror -t %d &&"+
" rabbitmq-upgrade await_online_synchronized_mirror -t %d || true &&"+
" rabbitmq-upgrade drain -t %d",
*builder.Instance.Spec.TerminationGracePeriodSeconds,
*builder.Instance.Spec.TerminationGracePeriodSeconds,
Expand Down
4 changes: 2 additions & 2 deletions internal/resource/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,15 +1447,15 @@ default_pass = {{ .Data.data.password }}
Expect(gracePeriodSeconds).To(Equal(ptr.To(int64(10))))

// TerminationGracePeriodSeconds is used to set commands timeouts in the preStop hook
expectedPreStopCommand := []string{"/bin/bash", "-c", "if [ ! -z \"$(cat /etc/pod-info/skipPreStopChecks)\" ]; then exit 0; fi; rabbitmq-upgrade await_online_quorum_plus_one -t 10 && rabbitmq-upgrade await_online_synchronized_mirror -t 10 && rabbitmq-upgrade drain -t 10"}
expectedPreStopCommand := []string{"/bin/bash", "-c", "if [ ! -z \"$(cat /etc/pod-info/skipPreStopChecks)\" ]; then exit 0; fi; rabbitmq-upgrade await_online_quorum_plus_one -t 10 && rabbitmq-upgrade await_online_synchronized_mirror -t 10 || true && rabbitmq-upgrade drain -t 10"}
Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal(expectedPreStopCommand))
})

It("checks mirror and quorum queue status in preStop hook", func() {
stsBuilder := builder.StatefulSet()
Expect(stsBuilder.Update(statefulSet)).To(Succeed())

expectedPreStopCommand := []string{"/bin/bash", "-c", "if [ ! -z \"$(cat /etc/pod-info/skipPreStopChecks)\" ]; then exit 0; fi; rabbitmq-upgrade await_online_quorum_plus_one -t 604800 && rabbitmq-upgrade await_online_synchronized_mirror -t 604800 && rabbitmq-upgrade drain -t 604800"}
expectedPreStopCommand := []string{"/bin/bash", "-c", "if [ ! -z \"$(cat /etc/pod-info/skipPreStopChecks)\" ]; then exit 0; fi; rabbitmq-upgrade await_online_quorum_plus_one -t 604800 && rabbitmq-upgrade await_online_synchronized_mirror -t 604800 || true && rabbitmq-upgrade drain -t 604800"}

Expect(statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command).To(Equal(expectedPreStopCommand))
})
Expand Down

0 comments on commit aa72d5d

Please sign in to comment.