diff options
| author | Raj Singh <raj@tailscale.com> | 2025-10-26 02:54:35 -0500 |
|---|---|---|
| committer | Raj Singh <raj@tailscale.com> | 2025-10-26 02:54:35 -0500 |
| commit | 146f5038f551e4c7a9a6261d42b4799c3ae985bc (patch) | |
| tree | 0fcd70fdfafc0cf62be87491f5ee19e76134c30d | |
| parent | 4346615d77a6de16854c6e78f9d49375d6424e6e (diff) | |
| download | tailscale-containerboot-exit-code.tar.xz tailscale-containerboot-exit-code.zip | |
cmd/containerboot: exit with non-zero code on unexpected tailscaled deathcontainerboot-exit-code
When tailscaled exits unexpectedly (crashes, killed directly), containerboot now exits with a non-zero code to signal failure to the orchestrator. The reaper now distinguishes between graceful shutdowns which still exit 0, and unexpected exits which propagate the child's exit code or force 1 if the child exited cleanly on its own. Fixes #17650
Signed-off-by: Raj Singh <raj@tailscale.com>
| -rw-r--r-- | cmd/containerboot/main.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/cmd/containerboot/main.go b/cmd/containerboot/main.go index f056d26f3..eafc77de2 100644 --- a/cmd/containerboot/main.go +++ b/cmd/containerboot/main.go @@ -728,8 +728,35 @@ runLoop: if err != nil { log.Fatalf("Waiting for tailscaled to exit: %v", err) } - log.Print("tailscaled exited") - os.Exit(0) + + // Distinguish between graceful shutdown and unexpected failure. + // Graceful shutdown (SIGTERM/SIGINT to containerboot) should exit 0 + // so Kubernetes treats the pod as completed successfully. + // Unexpected failures should exit non-zero so Kubernetes restarts the pod. + select { + case <-ctx.Done(): + // Graceful shutdown: containerboot received SIGTERM/SIGINT + // and told tailscaled to exit. This is expected, exit 0. + log.Print("tailscaled exited after graceful shutdown") + os.Exit(0) + default: + // Unexpected exit: tailscaled crashed or was killed directly. + // Exit non-zero to signal failure to the orchestrator. + exitCode := 1 + if status.Exited() { + exitCode = status.ExitStatus() + } else if status.Signaled() { + log.Printf("tailscaled terminated by signal: %v", status.Signal()) + exitCode = 128 + int(status.Signal()) + } + log.Printf("tailscaled exited unexpectedly with code %d", exitCode) + if exitCode == 0 { + // If tailscaled exited cleanly on its own, this is still unexpected. + // Force non-zero to ensure the container orchestrator restarts us. + exitCode = 1 + } + os.Exit(exitCode) + } } } wg.Add(1) |
