Skip to content
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
abhinavdahiya merged 2 commits into
release-1.22.9-lyft.3from
fix_container_wait
May 1, 2023
Merged

sidecar ordering: handle case where there is no known container state#35
abhinavdahiya merged 2 commits into
release-1.22.9-lyft.3from
fix_container_wait

Conversation

@abhinavdahiya
Copy link
Copy Markdown

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.

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.:


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.
@abhinavdahiya abhinavdahiya changed the title handle case where there is no known container state sidecar ordering: handle case where there is no known container state Apr 21, 2023
@abhinavdahiya
Copy link
Copy Markdown
Author

ptal #compute @tomwans

Comment thread pkg/kubelet/status/status_manager.go Outdated
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) ||
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

https://go.dev/play/p/KmoJ9g__5pp

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to comparing to zero value.

@abhinavdahiya abhinavdahiya changed the base branch from release-1.22.9-lyft.2 to release-1.22.9-lyft.3 May 1, 2023 17:11
@abhinavdahiya abhinavdahiya merged commit 04127ec into release-1.22.9-lyft.3 May 1, 2023
@abhinavdahiya abhinavdahiya deleted the fix_container_wait branch May 1, 2023 19:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants