mirror of https://github.com/k3s-io/k3s
Sort the daemon pods by creation time
parent
3902f76512
commit
b1412997d6
|
@ -366,7 +366,8 @@ func (dsc *DaemonSetsController) manage(ds *experimental.DaemonSet) {
|
||||||
nodesNeedingDaemonPods = append(nodesNeedingDaemonPods, nodeName)
|
nodesNeedingDaemonPods = append(nodesNeedingDaemonPods, nodeName)
|
||||||
} else if shouldRun && len(daemonPods) > 1 {
|
} else if shouldRun && len(daemonPods) > 1 {
|
||||||
// If daemon pod is supposed to be running on node, but more than 1 daemon pod is running, delete the excess daemon pods.
|
// If daemon pod is supposed to be running on node, but more than 1 daemon pod is running, delete the excess daemon pods.
|
||||||
// TODO: sort the daemon pods by creation time, so the the oldest is preserved.
|
// Sort the daemon pods by creation time, so the the oldest is preserved.
|
||||||
|
sort.Sort(podByCreationTimestamp(daemonPods))
|
||||||
for i := 1; i < len(daemonPods); i++ {
|
for i := 1; i < len(daemonPods); i++ {
|
||||||
podsToDelete = append(podsToDelete, daemonPods[i].Name)
|
podsToDelete = append(podsToDelete, daemonPods[i].Name)
|
||||||
}
|
}
|
||||||
|
@ -519,3 +520,15 @@ func (o byCreationTimestamp) Less(i, j int) bool {
|
||||||
}
|
}
|
||||||
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
|
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type podByCreationTimestamp []*api.Pod
|
||||||
|
|
||||||
|
func (o podByCreationTimestamp) Len() int { return len(o) }
|
||||||
|
func (o podByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
|
||||||
|
|
||||||
|
func (o podByCreationTimestamp) Less(i, j int) bool {
|
||||||
|
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
|
||||||
|
return o[i].Name < o[j].Name
|
||||||
|
}
|
||||||
|
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue