@@ -64,8 +64,8 @@ type DrainNodeHandler struct {
6464}
6565
6666type nodePods struct {
67- toEvict []v1.Pod
68- nonEvictable []v1.Pod
67+ toEvict []* v1.Pod
68+ nonEvictable []* v1.Pod
6969}
7070
7171func (h * DrainNodeHandler ) Handle (ctx context.Context , action * castai.ClusterAction ) error {
@@ -103,7 +103,7 @@ func (h *DrainNodeHandler) Handle(ctx context.Context, action *castai.ClusterAct
103103
104104 log .Info ("cordoning node for draining" )
105105
106- if err : = k8s .CordonNode (ctx , h .log , h .clientset , node ); err != nil {
106+ if err = k8s .CordonNode (ctx , h .log , h .clientset , node ); err != nil {
107107 return fmt .Errorf ("cordoning node %q: %w" , req .NodeName , err )
108108 }
109109
@@ -177,7 +177,7 @@ func (h *DrainNodeHandler) Handle(ctx context.Context, action *castai.ClusterAct
177177// waitForVolumeDetachIfEnabled waits for VolumeAttachments to be deleted if the feature is enabled.
178178// This is called after successful drain to give CSI drivers time to clean up volumes.
179179// nonEvictablePods are pods that won't be evicted (DaemonSet, static) - their was are excluded from waiting.
180- func (h * DrainNodeHandler ) waitForVolumeDetachIfEnabled (ctx context.Context , log logrus.FieldLogger , nodeName string , req * castai.ActionDrainNode , nonEvictablePods []v1.Pod ) {
180+ func (h * DrainNodeHandler ) waitForVolumeDetachIfEnabled (ctx context.Context , log logrus.FieldLogger , nodeName string , req * castai.ActionDrainNode , nonEvictablePods []* v1.Pod ) {
181181 if ! ShouldWaitForVolumeDetach (req ) || h .vaWaiter == nil {
182182 return
183183 }
@@ -204,7 +204,7 @@ func (h *DrainNodeHandler) waitForVolumeDetachIfEnabled(ctx context.Context, log
204204// The method will still wait for termination of other evicted pods first.
205205// Returns non-evictable pods (DaemonSet, static).
206206// A return value of (pods, nil) means all evictable pods on the node should be evicted and terminated.
207- func (h * DrainNodeHandler ) evictNodePods (ctx context.Context , log logrus.FieldLogger , node * v1.Node ) ([]v1.Pod , error ) {
207+ func (h * DrainNodeHandler ) evictNodePods (ctx context.Context , log logrus.FieldLogger , node * v1.Node ) ([]* v1.Pod , error ) {
208208 nodePods , err := h .listNodePods (ctx , log , node )
209209 if err != nil {
210210 return nil , err
@@ -257,7 +257,7 @@ func (h *DrainNodeHandler) evictNodePods(ctx context.Context, log logrus.FieldLo
257257// The method will still wait for termination of other deleted pods first.
258258// Returns non-evictable pods (DaemonSet, static).
259259// A return value of (pods, nil) means all evictable pods on the node should be deleted and terminated.
260- func (h * DrainNodeHandler ) deleteNodePods (ctx context.Context , log logrus.FieldLogger , node * v1.Node , options metav1.DeleteOptions ) ([]v1.Pod , error ) {
260+ func (h * DrainNodeHandler ) deleteNodePods (ctx context.Context , log logrus.FieldLogger , node * v1.Node , options metav1.DeleteOptions ) ([]* v1.Pod , error ) {
261261 nodePods , err := h .listNodePods (ctx , log , node )
262262 if err != nil {
263263 return nil , err
@@ -338,11 +338,16 @@ func (h *DrainNodeHandler) listNodePods(ctx context.Context, log logrus.FieldLog
338338 return nil , fmt .Errorf ("listing node %v pods: %w" , node .Name , err )
339339 }
340340
341- partitioned := k8s .PartitionPodsForEviction (pods .Items , h .cfg .castNamespace , h .cfg .skipDeletedTimeoutSeconds )
341+ podPtrs := make ([]* v1.Pod , len (pods .Items ))
342+ for i := range pods .Items {
343+ podPtrs [i ] = & pods .Items [i ]
344+ }
345+
346+ partitioned := k8s .PartitionPodsForEviction (podPtrs , h .cfg .castNamespace , h .cfg .skipDeletedTimeoutSeconds )
342347
343348 result := & nodePods {
344- toEvict : make ([]v1.Pod , 0 , len (partitioned .Evictable )+ len (partitioned .CastPods )),
345- nonEvictable : make ([]v1.Pod , 0 , len (partitioned .NonEvictable )),
349+ toEvict : make ([]* v1.Pod , 0 , len (partitioned .Evictable )+ len (partitioned .CastPods )),
350+ nonEvictable : make ([]* v1.Pod , 0 , len (partitioned .NonEvictable )),
346351 }
347352
348353 logCastPodsToEvict (log , partitioned .CastPods )
@@ -381,7 +386,7 @@ func (h *DrainNodeHandler) waitNodePodsTerminated(ctx context.Context, log logru
381386 return true , fmt .Errorf ("listing %q pods to be terminated: %w" , node .Name , err )
382387 }
383388
384- podsNames := lo .Map (nodePods .toEvict , func (p v1.Pod , _ int ) string {
389+ podsNames := lo .Map (nodePods .toEvict , func (p * v1.Pod , _ int ) string {
385390 return fmt .Sprintf ("%s/%s" , p .Namespace , p .Name )
386391 })
387392
@@ -403,7 +408,7 @@ func (h *DrainNodeHandler) waitNodePodsTerminated(ctx context.Context, log logru
403408 )
404409}
405410
406- func logCastPodsToEvict (log logrus.FieldLogger , castPods []v1.Pod ) {
411+ func logCastPodsToEvict (log logrus.FieldLogger , castPods []* v1.Pod ) {
407412 if len (castPods ) == 0 {
408413 return
409414 }
0 commit comments