@@ -25,6 +25,7 @@ import (
2525 "net"
2626 "os"
2727 "path/filepath"
28+ "slices"
2829 "strings"
2930 "time"
3031
@@ -105,7 +106,8 @@ func NewLogDumper(bastionAddress string, sshConfig *ssh.ClientConfig, keyRing ag
105106// This allows for dumping log on nodes even if they don't register as a kubernetes
106107// node, or if a node fails to register, or if the whole cluster fails to start.
107108func (d * logDumper ) DumpAllNodes (ctx context.Context , nodes corev1.NodeList , maxNodesToDump int , additionalIPs , additionalPrivateIPs []string ) error {
108- var special , regular , dumped []* corev1.Node
109+ var special , regular []* corev1.Node
110+ var dumped []string
109111
110112 log .Printf ("starting to dump %d nodes fetched through the Kubernetes APIs" , len (nodes .Items ))
111113 for i := range nodes .Items {
@@ -129,11 +131,11 @@ func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, max
129131
130132 for i := range special {
131133 node := special [i ]
132- err := d .dumpRegistered (ctx , node )
134+ ip , err := d .dumpRegistered (ctx , node )
133135 if err != nil {
134136 log .Printf ("could not dump node %s: %v" , node .Name , err )
135137 } else {
136- dumped = append (dumped , node )
138+ dumped = append (dumped , ip )
137139 }
138140 }
139141
@@ -143,11 +145,11 @@ func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, max
143145 return nil
144146 }
145147 node := regular [i ]
146- err := d .dumpRegistered (ctx , node )
148+ ip , err := d .dumpRegistered (ctx , node )
147149 if err != nil {
148150 log .Printf ("could not dump node %s: %v" , node .Name , err )
149151 } else {
150- dumped = append (dumped , node )
152+ dumped = append (dumped , ip )
151153 }
152154 }
153155
@@ -161,6 +163,7 @@ func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, max
161163 if err != nil {
162164 return err
163165 }
166+ dumped = append (dumped , ip )
164167 }
165168
166169 notDumped = findInstancesNotDumped (additionalPrivateIPs , dumped )
@@ -173,15 +176,16 @@ func (d *logDumper) DumpAllNodes(ctx context.Context, nodes corev1.NodeList, max
173176 if err != nil {
174177 return err
175178 }
179+ dumped = append (dumped , ip )
176180 }
177181
178182 return nil
179183}
180184
181- func (d * logDumper ) dumpRegistered (ctx context.Context , node * corev1.Node ) error {
185+ func (d * logDumper ) dumpRegistered (ctx context.Context , node * corev1.Node ) ( string , error ) {
182186 if ctx .Err () != nil {
183187 log .Printf ("stopping dumping nodes: %v" , ctx .Err ())
184- return ctx .Err ()
188+ return "" , ctx .Err ()
185189 }
186190
187191 var publicIP , privateIP string
@@ -197,14 +201,14 @@ func (d *logDumper) dumpRegistered(ctx context.Context, node *corev1.Node) error
197201 }
198202
199203 if publicIP != "" {
200- return d .dumpNode (ctx , node .Name , publicIP , false )
204+ return publicIP , d .dumpNode (ctx , node .Name , publicIP , false )
201205 } else {
202206 useBastion := true
203207 if ! d .sshClientFactory .HasBastion () {
204208 klog .Warningf ("no bastion address set, will attempt to connect to node %s directly via private IP %v" , node .Name , privateIP )
205209 useBastion = false
206210 }
207- return d .dumpNode (ctx , node .Name , privateIP , useBastion )
211+ return privateIP , d .dumpNode (ctx , node .Name , privateIP , useBastion )
208212 }
209213}
210214
@@ -223,17 +227,10 @@ func (d *logDumper) dumpNotRegistered(ctx context.Context, ip string, useBastion
223227}
224228
225229// findInstancesNotDumped returns ips from the slice that do not appear as any address of the nodes
226- func findInstancesNotDumped (ips [] string , dumped []* corev1. Node ) []string {
230+ func findInstancesNotDumped (ips , dumped []string ) []string {
227231 var notDumped []string
228- dumpedAddresses := make (map [string ]bool )
229- for _ , node := range dumped {
230- for _ , address := range node .Status .Addresses {
231- dumpedAddresses [address .Address ] = true
232- }
233- }
234-
235232 for _ , ip := range ips {
236- if ! dumpedAddresses [ ip ] {
233+ if ! slices . Contains ( dumped , ip ) {
237234 notDumped = append (notDumped , ip )
238235 }
239236 }
0 commit comments