@@ -34,6 +34,8 @@ import (
34
34
"k8s.io/klog/v2"
35
35
ctrl "sigs.k8s.io/controller-runtime"
36
36
"sigs.k8s.io/controller-runtime/pkg/client"
37
+
38
+ clog "sigs.k8s.io/cluster-api/util/log"
37
39
)
38
40
39
41
// Helper contains the parameters to control the behaviour of the drain helper.
@@ -351,33 +353,14 @@ func (r EvictionResult) ConditionMessage() string {
351
353
352
354
// podDeleteListToString returns a comma-separated list of the first n entries of the PodDelete list.
353
355
func podDeleteListToString (podList []PodDelete , n int ) string {
354
- return listToString (podList , func (pd PodDelete ) string {
356
+ return clog . ListToString (podList , func (pd PodDelete ) string {
355
357
return klog .KObj (pd .Pod ).String ()
356
358
}, n )
357
359
}
358
360
359
361
// PodListToString returns a comma-separated list of the first n entries of the Pod list.
360
362
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 {
362
364
return klog .KObj (p ).String ()
363
365
}, n )
364
366
}
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
- }
0 commit comments