Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions internal/controllers/machine/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

clog "sigs.k8s.io/cluster-api/util/log"
)

// Helper contains the parameters to control the behaviour of the drain helper.
Expand Down Expand Up @@ -351,33 +353,14 @@ func (r EvictionResult) ConditionMessage(nodeDrainStartTime *metav1.Time) string

// podDeleteListToString returns a comma-separated list of the first n entries of the PodDelete list.
func podDeleteListToString(podList []PodDelete, n int) string {
return listToString(podList, func(pd PodDelete) string {
return clog.ListToString(podList, func(pd PodDelete) string {
return klog.KObj(pd.Pod).String()
}, n)
}

// PodListToString returns a comma-separated list of the first n entries of the Pod list.
func PodListToString(podList []*corev1.Pod, n int) string {
return listToString(podList, func(p *corev1.Pod) string {
return clog.ListToString(podList, func(p *corev1.Pod) string {
return klog.KObj(p).String()
}, n)
}

// listToString returns a comma-separated list of the first n entries of the list (strings are calculated via stringFunc).
func listToString[T any](list []T, stringFunc func(T) string, n int) string {
shortenedBy := 0
if len(list) > n {
shortenedBy = len(list) - n
list = list[:n]
}
stringList := []string{}
for _, p := range list {
stringList = append(stringList, stringFunc(p))
}

if shortenedBy > 0 {
stringList = append(stringList, fmt.Sprintf("... (%d more)", shortenedBy))
}

return strings.Join(stringList, ", ")
}
12 changes: 12 additions & 0 deletions internal/controllers/machine/drain/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ func (l *PodDeleteList) Pods() []*corev1.Pod {
return pods
}

// IgnoredPods returns a list of Pods that have to be ignored before the Node can be considered completely drained.
// Note: As of today only Pods from DaemonSet, static Pods or if `SkipWaitForDeleteTimeoutSeconds` is set Pods in deletion get ignored.
func (l *PodDeleteList) IgnoredPods() []*corev1.Pod {
pods := []*corev1.Pod{}
for _, i := range l.items {
if !i.Status.Delete {
pods = append(pods, i.Pod)
}
}
return pods
}

func (l *PodDeleteList) errors() []error {
failedPods := make(map[string][]string)
for _, i := range l.items {
Expand Down
Loading