Skip to content

Commit c0ee548

Browse files
committed
fixup! feat: timeout the postStart hook commands
Signed-off-by: Oleksii Kurinnyi <[email protected]>
1 parent 095b2f2 commit c0ee548

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

pkg/library/status/check.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ import (
3131
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
3232
)
3333

34+
var (
35+
// reTerminatedSigterm matches: "[postStart hook] Commands terminated by SIGTERM (likely timed out after ...s). Exit code 143."
36+
reTerminatedSigterm = regexp.MustCompile(`(\\[postStart hook\\] Commands terminated by SIGTERM \\(likely timed out after [^)]+?\\)\\. Exit code 143\\.)`)
37+
38+
// reKilledSigkill matches: "[postStart hook] Commands forcefully killed by SIGKILL (likely after --kill-after ...s expired). Exit code 137."
39+
reKilledSigkill = regexp.MustCompile(`(\\[postStart hook\\] Commands forcefully killed by SIGKILL \\(likely after --kill-after [^)]+?\\)\\. Exit code 137\\.)`)
40+
41+
// reGenericFailedExitCode matches: "[postStart hook] Commands failed with exit code ..." (for any other script-reported non-zero exit code)
42+
reGenericFailedExitCode = regexp.MustCompile(`(\\[postStart hook\\] Commands failed with exit code \\d+\\.)`)
43+
44+
// reKubeletInternalMessage regex to capture Kubelet's explicit message field content if it exists
45+
reKubeletInternalMessage = regexp.MustCompile(`message:\\s*"([^"]*)"`)
46+
47+
// reKubeletExitCode regex to capture Kubelet's reported exit code for the hook command
48+
reKubeletExitCode = regexp.MustCompile(`exited with (\\d+):`)
49+
)
50+
3451
var containerFailureStateReasons = []string{
3552
"CrashLoopBackOff",
3653
"ImagePullBackOff",
@@ -166,25 +183,7 @@ func CheckPodEvents(pod *corev1.Pod, workspaceID string, ignoredEvents []string,
166183
// getConcisePostStartFailureMessage tries to parse the Kubelet's verbose message
167184
// for a PostStartHookError into a more user-friendly one.
168185
func getConcisePostStartFailureMessage(kubeletMsg string) string {
169-
170-
/* regexes for specific messages from our postStart script's output */
171-
172-
// matches: "[postStart hook] Commands terminated by SIGTERM (likely timed out after ...s). Exit code 143."
173-
reTerminatedSigterm := regexp.MustCompile(`(\[postStart hook\] Commands terminated by SIGTERM \(likely timed out after [^)]+?\)\. Exit code 143\.)`)
174-
175-
// matches: "[postStart hook] Commands forcefully killed by SIGKILL (likely after --kill-after ...s expired). Exit code 137."
176-
reKilledSigkill := regexp.MustCompile(`(\[postStart hook\] Commands forcefully killed by SIGKILL \(likely after --kill-after [^)]+?\)\. Exit code 137\.)`)
177-
178-
// matches: "[postStart hook] Commands failed with exit code ..." (for any other script-reported non-zero exit code)
179-
reGenericFailedExitCode := regexp.MustCompile(`(\[postStart hook\] Commands failed with exit code \d+\.)`)
180-
181-
// regex to capture Kubelet's explicit message field content if it exists
182-
reKubeletInternalMessage := regexp.MustCompile(`message:\s*"([^"]*)"`)
183-
184-
// regex to capture Kubelet's reported exit code for the hook command
185-
reKubeletExitCode := regexp.MustCompile(`exited with (\d+):`)
186-
187-
/* 1: check Kubelet's explicit `message: "..."` field for the specific output */
186+
/* 1: check Kubelet's explicit 'message: "..."' field for the specific output */
188187

189188
kubeletInternalMsgMatch := reKubeletInternalMessage.FindStringSubmatch(kubeletMsg)
190189
if len(kubeletInternalMsgMatch) > 1 && kubeletInternalMsgMatch[1] != "" {

0 commit comments

Comments
 (0)