Skip to content

Commit 508beae

Browse files
authored
⚠️ Machine: ignore attached Volumes referred by pods ignored during drain (#11246)
* Machine: ignore attached Volumes referred by pods ignored during drain * inmemory: add support for storage.k8s.io/v1 volumeattachments * add more details to the v1beta2 deleting condition * review fixes
1 parent f1b1174 commit 508beae

File tree

7 files changed

+681
-64
lines changed

7 files changed

+681
-64
lines changed

internal/controllers/machine/drain/drain.go

+4-21
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"k8s.io/klog/v2"
3535
ctrl "sigs.k8s.io/controller-runtime"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
37+
38+
clog "sigs.k8s.io/cluster-api/util/log"
3739
)
3840

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

352354
// podDeleteListToString returns a comma-separated list of the first n entries of the PodDelete list.
353355
func podDeleteListToString(podList []PodDelete, n int) string {
354-
return listToString(podList, func(pd PodDelete) string {
356+
return clog.ListToString(podList, func(pd PodDelete) string {
355357
return klog.KObj(pd.Pod).String()
356358
}, n)
357359
}
358360

359361
// PodListToString returns a comma-separated list of the first n entries of the Pod list.
360362
func PodListToString(podList []*corev1.Pod, n int) string {
361-
return listToString(podList, func(p *corev1.Pod) string {
363+
return clog.ListToString(podList, func(p *corev1.Pod) string {
362364
return klog.KObj(p).String()
363365
}, n)
364366
}
365-
366-
// listToString returns a comma-separated list of the first n entries of the list (strings are calculated via stringFunc).
367-
func listToString[T any](list []T, stringFunc func(T) string, n int) string {
368-
shortenedBy := 0
369-
if len(list) > n {
370-
shortenedBy = len(list) - n
371-
list = list[:n]
372-
}
373-
stringList := []string{}
374-
for _, p := range list {
375-
stringList = append(stringList, stringFunc(p))
376-
}
377-
378-
if shortenedBy > 0 {
379-
stringList = append(stringList, fmt.Sprintf("... (%d more)", shortenedBy))
380-
}
381-
382-
return strings.Join(stringList, ", ")
383-
}

internal/controllers/machine/drain/filters.go

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ func (l *PodDeleteList) Pods() []*corev1.Pod {
6262
return pods
6363
}
6464

65+
// IgnoredPods returns a list of Pods that have to be ignored before the Node can be considered completely drained.
66+
// Note: As of today only Pods from DaemonSet, static Pods or if `SkipWaitForDeleteTimeoutSeconds` is set Pods in deletion get ignored.
67+
func (l *PodDeleteList) IgnoredPods() []*corev1.Pod {
68+
pods := []*corev1.Pod{}
69+
for _, i := range l.items {
70+
if !i.Status.Delete {
71+
pods = append(pods, i.Pod)
72+
}
73+
}
74+
return pods
75+
}
76+
6577
func (l *PodDeleteList) errors() []error {
6678
failedPods := make(map[string][]string)
6779
for _, i := range l.items {

0 commit comments

Comments
 (0)