mon: trap the sigterm in the mon canary

The mon canary should quickly shut down after the pod is
deleted, since it has no purpose to continue running.
Since the sleep does not catch the SIGTERM as pid 1,
use a bash trap to exit quickly.

Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
(cherry picked from commit 48b70500fa)
This commit is contained in:
Travis Nielsen authored and Mergify committed 2025-10-23 05:49:20 +00:00
1 parent e239749916
commit 6f799052eb
1 file changed
+9 -2
+9 -2
View File
@@ -703,8 +703,15 @@ func scheduleMonitor(c *Cluster, mon *monConfig) (*apps.Deployment, error) {
// to modify the storage by instead running an innocuous command.
d.Spec.Template.Spec.InitContainers = []corev1.Container{}
d.Spec.Template.Spec.Containers[0].Image = c.rookImage
d.Spec.Template.Spec.Containers[0].Command = []string{"sleep"} // sleep responds to signals so we don't need to wrap it
d.Spec.Template.Spec.Containers[0].Args = []string{"3600"}
// As PID 1, sleep will not capture the SIGTERM signal, so use a bash
// trap to exit cleanly and quickly when the pod is deleted.
d.Spec.Template.Spec.Containers[0].Command = []string{
"/bin/bash",
"-c",
`trap 'exit' SIGTERM
while true; do sleep 1; done`,
}
// remove the startup and liveness probes on the canary pod
d.Spec.Template.Spec.Containers[0].StartupProbe = nil
d.Spec.Template.Spec.Containers[0].LivenessProbe = nil