There is a clue showing that they can have a different order and even differ in size: https://github.com/kubernetes/kubernetes/blob/v1.28.1/pkg/kubelet/kubelet.go#L2708-L2717
...
for _, container := range pod.Spec.Containers {
if len(container.Resources.Requests) == 0 {
continue
}
containerStatus, found := podutil.GetContainerStatus(pod.Status.ContainerStatuses, container.Name)
if !found {
klog.V(5).InfoS("ContainerStatus not found", "pod", pod.Name, "container", container.Name)
break
}
...
Each ContainterStatus
is retrieved by Container.Name
, not by the index of Container
in its containing list.
I wanted to know why they are treated as unordered sets not ordered lists. I have searched the Internet spending for over an hour and failed to find any.
Does anybody know the answer?