@@ -264,7 +264,8 @@ func (kh *K8sHandler) getKaPodInformer(ipsChan chan string) cache.SharedIndexInf
264264 }
265265
266266 if pod .Status .PodIP != "" {
267- ipsChan <- pod .Status .PodIP
267+ // generate id <pod-name>:<pod-ip>
268+ ipsChan <- generateID (pod .Name , pod .Status .PodIP )
268269 }
269270 },
270271 UpdateFunc : func (old , new interface {}) {
@@ -279,8 +280,10 @@ func (kh *K8sHandler) getKaPodInformer(ipsChan chan string) cache.SharedIndexInf
279280 }
280281
281282 if newPod .Status .PodIP != "" && newPod .Status .PodIP != oldPod .Status .PodIP {
282- ipsChan <- newPod .Status .PodIP
283- DeleteClientEntry (oldPod .Status .PodIP )
283+ if oldPod .Status .PodIP != "" {
284+ DeleteClientEntry (generateID (oldPod .Name , oldPod .Status .PodIP ))
285+ }
286+ ipsChan <- generateID (newPod .Name , newPod .Status .PodIP )
284287 }
285288 },
286289 DeleteFunc : func (obj interface {}) {
@@ -290,7 +293,7 @@ func (kh *K8sHandler) getKaPodInformer(ipsChan chan string) cache.SharedIndexInf
290293 }
291294
292295 if pod .Status .PodIP != "" {
293- DeleteClientEntry (pod .Status .PodIP )
296+ DeleteClientEntry (generateID ( pod .Name , pod . Status .PodIP ) )
294297 }
295298 },
296299 })
@@ -310,7 +313,23 @@ func (kh *K8sHandler) findExistingKaPodsIp(ctx context.Context, ipsChan chan str
310313
311314 for _ , pod := range pods .Items {
312315 if pod .Status .PodIP != "" {
313- ipsChan <- pod .Status .PodIP
316+ ipsChan <- generateID ( pod .Name , pod . Status .PodIP )
314317 }
315318 }
316319}
320+
321+ // ===========
322+ // == utils ==
323+ // ===========
324+
325+ func generateID (podName , podIP string ) string {
326+ return fmt .Sprintf ("%s:%s" , podName , podIP )
327+ }
328+
329+ func extractIP (podID string ) (string , error ) {
330+ id := strings .Split (podID , ":" )
331+ if len (id ) != 2 {
332+ return "" , fmt .Errorf ("invalid ID format: %s" , podID )
333+ }
334+ return id [1 ], nil
335+ }
0 commit comments