Skip to content

Commit

Permalink
fix(ecmp_vip.go): ClusterIP -> ClusterIPs
Browse files Browse the repository at this point in the history
Use ClusterIPs rather than ClusterIP so that we get all of the possible
IP addresses rather than just one.

Fixes #1443
  • Loading branch information
aauren committed Oct 7, 2023
1 parent fe93978 commit 57c9b08
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions pkg/controllers/routing/ecmp_vip.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,28 @@ func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) {
nrc.tryHandleServiceUpdate(svc, "Updating service %s/%s triggered by endpoint update event")
}

func (nrc *NetworkRoutingController) getClusterIP(svc *v1core.Service) string {
clusterIP := ""
func (nrc *NetworkRoutingController) getClusterIP(svc *v1core.Service) []string {
clusterIPList := make([]string, 0)
if svc.Spec.Type == ClusterIPST || svc.Spec.Type == NodePortST || svc.Spec.Type == LoadBalancerST {

// skip headless services
if !utils.ClusterIPIsNoneOrBlank(svc.Spec.ClusterIP) {
clusterIP = svc.Spec.ClusterIP
clusterIPList = append(clusterIPList, svc.Spec.ClusterIPs...)
// check to ensure ClusterIP is contained within ClusterIPs - This should always be the case, but we check
// just to make extra sure
clusterIPFound := false
for _, clusterIP := range clusterIPList {
if svc.Spec.ClusterIP == clusterIP {
clusterIPFound = true
break
}
}
if !clusterIPFound {
clusterIPList = append(clusterIPList, svc.Spec.ClusterIP)
}
}
}
return clusterIP
return clusterIPList
}

func (nrc *NetworkRoutingController) getExternalIPs(svc *v1core.Service) []string {
Expand Down Expand Up @@ -487,12 +499,12 @@ func (nrc *NetworkRoutingController) getAllVIPsForService(svc *v1core.Service) (
advertisedIPList := make([]string, 0)
unAdvertisedIPList := make([]string, 0)

clusterIP := nrc.getClusterIP(svc)
if clusterIP != "" {
clusterIPs := nrc.getClusterIP(svc)
if len(clusterIPs) > 0 {
if nrc.shouldAdvertiseService(svc, svcAdvertiseClusterAnnotation, nrc.advertiseClusterIP) {
advertisedIPList = append(advertisedIPList, clusterIP)
advertisedIPList = append(advertisedIPList, clusterIPs...)
} else {
unAdvertisedIPList = append(unAdvertisedIPList, clusterIP)
unAdvertisedIPList = append(unAdvertisedIPList, clusterIPs...)
}
}

Expand Down

0 comments on commit 57c9b08

Please sign in to comment.