mirror of https://github.com/k3s-io/k3s
kubelet: Sort the container statuses in convertStatusToAPIStatus().
parent
6327ea9bd2
commit
168ec8b80f
|
@ -470,3 +470,12 @@ func ParsePodFullName(podFullName string) (string, string, error) {
|
|||
// Option is a functional option type for Runtime, useful for
|
||||
// completely optional settings.
|
||||
type Option func(Runtime)
|
||||
|
||||
// Sort the container statuses by creation time.
|
||||
type SortContainerStatusesByCreationTime []*ContainerStatus
|
||||
|
||||
func (s SortContainerStatusesByCreationTime) Len() int { return len(s) }
|
||||
func (s SortContainerStatusesByCreationTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s SortContainerStatusesByCreationTime) Less(i, j int) bool {
|
||||
return s[i].CreatedAt.Before(s[j].CreatedAt)
|
||||
}
|
||||
|
|
|
@ -3276,6 +3276,9 @@ func (kl *Kubelet) convertStatusToAPIStatus(pod *api.Pod, podStatus *kubecontain
|
|||
return status
|
||||
}
|
||||
|
||||
// Make the latest container status comes first.
|
||||
sort.Sort(sort.Reverse(kubecontainer.SortContainerStatusesByCreationTime(podStatus.ContainerStatuses)))
|
||||
|
||||
statuses := make(map[string]*api.ContainerStatus, len(pod.Spec.Containers))
|
||||
// Create a map of expected containers based on the pod spec.
|
||||
expectedContainers := make(map[string]api.Container)
|
||||
|
|
|
@ -1482,9 +1482,3 @@ func (r *Runtime) GetPodStatus(uid types.UID, name, namespace string) (*kubecont
|
|||
|
||||
return podStatus, nil
|
||||
}
|
||||
|
||||
type sortByRestartCount []*kubecontainer.ContainerStatus
|
||||
|
||||
func (s sortByRestartCount) Len() int { return len(s) }
|
||||
func (s sortByRestartCount) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s sortByRestartCount) Less(i, j int) bool { return s[i].RestartCount < s[j].RestartCount }
|
||||
|
|
Loading…
Reference in New Issue