kubernetes/kubernetes

[Sidecar Containers] Pods comparison by maxContainerRestarts should account for sidecar containers

SergeyKanzhelev opened this issue · 2 comments

What happened?

Today, there are a few uses of the function maxContainerRestarts - mostly to compare pods to decide which one is
better to delete or which logs to get. This is not a huge issue, mostly a quality of life improvement.

The code only look at Container Statuses, but likely need to look at init container statuses as well.
Especially in case of sidecar containers that may behave exactly as regular containers.

There are 2 implementations and 5 comparison interfaces.

Implementatons in:

  • pkg/controller/controller_utils.go
  • staging/src/k8s.io/kubectl/pkg/util/podutils/podutils.go
func maxContainerRestarts(pod *v1.Pod) int {
	maxRestarts := 0
	for _, c := range pod.Status.ContainerStatuses {
		maxRestarts = max(maxRestarts, int(c.RestartCount))
	}
	return maxRestarts
}

We may need to be careful including all init container statuses. If a Pod was failing to start for a while
because of Init container failures and now it is running OK, it is likely not important. However, including
the restartable containers (sidecars) restart count is important.

I think the desireable behavior will be to check regular containers max restart count first. And compare this.
Then compare max restart count for restarteable init containers.

/kind bug

What did you expect to happen?

Comparison of max container restarts account for init containers as well as regular containers.

How can we reproduce it (as minimally and precisely as possible)?

Two pods - one with the sidecar container in constant restart loop and one is running sucessfully. Random one will be picked to get logs from.

Anything else we need to know?

/sig apps
/priority backlog

KEP: kubernetes/enhancements#753

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

/assign