This repository was archived by the owner on Apr 20, 2026. It is now read-only.
sidecar ordering: handle case where there is no known container state#35
Merged
Merged
Conversation
Based on the api documentation https://pkg.go.dev/k8s.io/api/core/v1#ContainerState ``` ContainerState holds a possible state of container. Only one of its members may be specified. If none of them is specified, the default one is ContainerStateWaiting. ``` There is a case where no explicit state is known for a container and it must be treated as waiting state. So we must check for nil value (since the State is a value and pointer we have to check that all possible fields are nil , :( ) and treat it as Waiting state. Also fixes the `Restart running non-sidecars despite sidecar becoming not ready` test. A pod if needs to be restarted (i.e it had existed and has run at least one) the state of the container should be set to last running state.
Author
|
ptal #compute @tomwans |
abhinavdahiya
commented
Apr 21, 2023
| klog.Infof("Pod: %s: %s: non-sidecar waiting", format.Pod(pod), container.Name) | ||
| sidecarsStatus.ContainersWaiting = true | ||
| } else { | ||
| if (status.State.Waiting == nil && status.State.Running == nil && status.State.Terminated == nil) || |
Author
There was a problem hiding this comment.
State is a value object and not a pointer, so to check for empty/unknown state kinda have to check all fields are nil.. feels clunky and might break if there are more fields.
There was a problem hiding this comment.
In the all nil case we can compare the zero value - this can still potentially break if new fields are added, but maybe this is a bit safer:
Suggested change
| if (status.State.Waiting == nil && status.State.Running == nil && status.State.Terminated == nil) || | |
| if (status.State == v1.ContainerState{}) || status.State.Waiting != nil |
Author
There was a problem hiding this comment.
changed to comparing to zero value.
tomwans
approved these changes
Apr 21, 2023
MHBauer
approved these changes
Apr 21, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on the api documentation
https://pkg.go.dev/k8s.io/api/core/v1#ContainerState
There is a case where no explicit state is known for a container and it must be treated as waiting state.
So we must check for nil value (since the State is a value and pointer we have to check that all possible fields are nil , :( ) and treat it as Waiting state.
Also fixes the
Restart running non-sidecars despite sidecar becoming not readytest. A pod if needs to be restarted (i.e it had existed and has run at least one) the state of the container should be set to last running state.What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: