Skip to content

Commit

Permalink
support to ExternalTrafficPolicy: modify GetServiceLocalEndpoints #6
Browse files Browse the repository at this point in the history
  • Loading branch information
backguynn committed May 26, 2023
1 parent 33f3a08 commit dd7b3e0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/k8s/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit dd7b3e0

Please sign in to comment.