From dd7b3e02efbacba2c6fd2d66a3c0e81822b3133e Mon Sep 17 00:00:00 2001 From: backguynn Date: Fri, 26 May 2023 16:15:35 +0900 Subject: [PATCH] support to ExternalTrafficPolicy: modify GetServiceLocalEndpoints #6 --- pkg/k8s/node.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/k8s/node.go b/pkg/k8s/node.go index 22c7fde..8ff1d24 100644 --- a/pkg/k8s/node.go +++ b/pkg/k8s/node.go @@ -55,7 +55,6 @@ func GetNodeAddr(node *v1.Node) (net.IP, error) { // GetServiceLocalEndpoints - Get HostIPs of pods belonging to the given service func GetServiceLocalEndpoints(kubeClient clientset.Interface, svc *corev1.Service) ([]string, error) { var epList []string - var epMap map[string]struct{} ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() @@ -66,12 +65,12 @@ func GetServiceLocalEndpoints(kubeClient clientset.Interface, svc *corev1.Servic return epList, err } + epMap := make(map[string]struct{}) for _, pod := range podList.Items { if pod.Status.HostIP != "" { if _, found := epMap[pod.Status.HostIP]; !found { - epList = append(epList, pod.Status.HostIP) - } else { epMap[pod.Status.HostIP] = struct{}{} + epList = append(epList, pod.Status.HostIP) } } }