From c78556fb4b90bbebb462f3440f217bed700bd8d9 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 2 May 2025 14:40:57 +0200 Subject: [PATCH 1/2] agnhost pause: report signal, support termination message Which signal really cause the pause command to exit may be relevant to know. By supporting the default /dev/termination-log, that information also shows up in the pod status and then is often already shown in output of E2E tests for unexpected pod failures. --- test/images/agnhost/pause/pause.go | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/test/images/agnhost/pause/pause.go b/test/images/agnhost/pause/pause.go index 3e8eba9f63a..aa1155e994b 100644 --- a/test/images/agnhost/pause/pause.go +++ b/test/images/agnhost/pause/pause.go @@ -36,21 +36,32 @@ var CmdPause = &cobra.Command{ func pause(cmd *cobra.Command, args []string) { fmt.Println("Paused") + sigCh := make(chan os.Signal, 1) - done := make(chan int, 1) - signal.Notify(sigCh, syscall.SIGINT) - signal.Notify(sigCh, syscall.SIGTERM) + signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) fmt.Println("Signals registered") - go func() { - sig := <-sigCh - switch sig { - case syscall.SIGINT: - done <- 1 - case syscall.SIGTERM: - done <- 2 - } - }() - result := <-done - fmt.Printf("exiting %d\n", result) + sig := <-sigCh + + // Pods using the agnhost image may choose to override the default + // termination message path. They then have to the TERMINATION_MESSAGE_PATH + // env variable. + // + // `terminationMessagePolicy: FallbackToLogsOnError` also works because + // the same message is also the last line of output. + terminationMessagePath := os.Getenv("TERMINATION_MESSAGE_PATH") + if terminationMessagePath == "" { + terminationMessagePath = "/dev/termination-log" + } + exitMsg := []byte(fmt.Sprintf("exiting because of signal %q\n", sig)) + _ = os.WriteFile(terminationMessagePath, exitMsg, 0644) + _, _ = os.Stdout.Write(exitMsg) + + var result int + switch sig { + case syscall.SIGINT: + result = 1 + case syscall.SIGTERM: + result = 2 + } os.Exit(result) } From 79891eac8bba14cfdd1f50c827f0f15279496ef3 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 2 May 2025 17:27:24 +0200 Subject: [PATCH 2/2] agnhost: bump version to 2.54 --- test/images/agnhost/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index 4de2b4a4b08..d74a9d37b71 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.53 +2.54