Introduce deadline for init containers#4960
Conversation
Greptile SummaryThis PR introduces a configurable
Confidence Score: 4/5The runtime logic is sound, but one newly added test contains a message string that doesn't match what the production code emits, meaning that test will fail on CI. The core init container deadline logic, sidecar exclusion, and internal/executor/podchecks/pod_checks_test.go — the message assertion in the first init container deadline test needs to match the production string. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[GetAction called] --> B[LastStatusChange pod]
B -->|error| C[return ActionWait]
B -->|ok| D{deadlineForInitContainers > 0?}
D -->|no| H
D -->|yes| E[getInitContainerState]
E --> F{first != nil AND last == nil AND elapsed > deadline?}
F -->|no| H[compute timeInState]
F -->|yes| G[return ActionFail / PodStartupIssue]
H --> I{timeInState > deadlineForNodeAssignment AND no node?}
I -->|yes| J[return ActionRetry / NoNodeAssigned]
I -->|no| K{timeInState > deadlineForUpdates AND bad node?}
K -->|yes| L[return ActionRetry / NoStatusUpdates]
K -->|no| M[eventChecks + containerStateChecks]
M --> N[return maxAction]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[GetAction called] --> B[LastStatusChange pod]
B -->|error| C[return ActionWait]
B -->|ok| D{deadlineForInitContainers > 0?}
D -->|no| H
D -->|yes| E[getInitContainerState]
E --> F{first != nil AND last == nil AND elapsed > deadline?}
F -->|no| H[compute timeInState]
F -->|yes| G[return ActionFail / PodStartupIssue]
H --> I{timeInState > deadlineForNodeAssignment AND no node?}
I -->|yes| J[return ActionRetry / NoNodeAssigned]
I -->|no| K{timeInState > deadlineForUpdates AND bad node?}
K -->|yes| L[return ActionRetry / NoStatusUpdates]
K -->|no| M[eventChecks + containerStateChecks]
M --> N[return maxAction]
Reviews (6): Last reviewed commit: "wip" | Re-trigger Greptile |
|
|
||
| func Test_GetAction_BadNodeButUnderTimeLimit(t *testing.T) { | ||
| podChecks := podChecksWithMocks(ActionWait, ActionWait) | ||
| result, cause, message := podChecks.GetAction(createBasicPod(true), []*v1.Event{}, 10*time.Second) | ||
| result, cause, message := podChecks.GetAction(createBasicPodInStateFor(true, 10*time.Second), []*v1.Event{}) | ||
| assert.Equal(t, result, ActionWait) |
There was a problem hiding this comment.
Missing test for init container in Waiting/CrashLoopBackoff state
There is test coverage for Waiting (before first start), Running, and Terminated (exit 0 and multi-container partial success), but no test for the state where an init container previously ran with a non-zero exit code and is now in Waiting state (CrashLoopBackoff). That scenario exercises the LastState gap described in the sibling comment on pod_checks.go, and a test would confirm whether the deadline is expected to fire or not during the backoff window.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Signed-off-by: Nikola Jokic <jokicnikola07@gmail.com>
Signed-off-by: Nikola Jokic <jokicnikola07@gmail.com>
Signed-off-by: Nikola Jokic <jokicnikola07@gmail.com>
What type of PR is this?
Enhancement
What this PR does / why we need it
Init containers could take time that is counted in the startup time of main containers. This change includes init containers so that checks related to the main container are based on the time where the last transition time occurred, including the init container state change.
The deadline doesn't include side-car containers (init containers with restart policy always).