Skip to content

Commit

Permalink
⚠️ Machine: ignore attached Volumes referred by pods ignored during d…
Browse files Browse the repository at this point in the history
…rain (#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
  • Loading branch information
chrischdi authored Oct 23, 2024
1 parent f1b1174 commit 508beae
Show file tree
Hide file tree
Showing 7 changed files with 681 additions and 64 deletions.
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

0 comments on commit 508beae

Please sign in to comment.