### 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: https://github.com/kubernetes/enhancements/issues/753
[Sidecar Containers] Pods comparison by maxContainerRestarts should account for sidecar containers
This is a GitHub Issue
repo:kubernetes
owner:kubernetes
Title : [Sidecar Containers] Pods comparison by maxContainerRestarts should account for sidecar containers
Issue date:

--- start body ---
### 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: https://github.com/kubernetes/enhancements/issues/753
--- end body ---
