Skip to content

Commit

Permalink
support for mixed port endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Dec 21, 2024
1 parent 6b523bd commit bd0e3f1
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
}

if !update {
update = m.checkUpdateEndpoints(cacheKey, endpointIPs) || m.checkUpdateExternalIP(ingSvcPairs, svc)
update = m.checkUpdateEndpoints(svc, cacheKey, endpointIPs, useExternalEndpoint) || m.checkUpdateExternalIP(ingSvcPairs, svc)
}

if !update {
Expand Down Expand Up @@ -1483,13 +1483,57 @@ func (m *Manager) checkUpdateExternalIP(ingSvcPairs []SvcPair, svc *corev1.Servi
return false
}

func (m *Manager) checkUpdateEndpoints(cacheKey string, endpointIPs []string) bool {
func (m *Manager) checkUpdateEndpoints(svc *corev1.Service, cacheKey string, endpointIPs []string, matchPorts bool) bool {
var update bool

for _, sp := range m.lbCache[cacheKey].LbServicePairs {
// Update external IP if has changed
if matchPorts {
loxiEndpointModelList := []api.LoadBalancerEndpoint{}
var tports []int
var err error
tports, err = k8s.GetServiceEndPointsPorts(m.kubeClient, svc)
if err != nil {
return true
}
for _, endpoint := range endpointIPs {
for _, tport := range tports {
loxiEndpointModelList = append(loxiEndpointModelList, api.LoadBalancerEndpoint{
EndpointIP: endpoint,
TargetPort: uint16(tport),
Weight: 1,
})
}
}

for _, sp := range m.lbCache[cacheKey].LbServicePairs {
// Check if external-endpoint list has changed
for _, lb := range sp.LbModelList {
if len(loxiEndpointModelList) == len(lb.Endpoints) {
for _, endpoint := range loxiEndpointModelList {
found := false
for _, oldEp := range lb.Endpoints {
if oldEp.EndpointIP == endpoint.EndpointIP &&
oldEp.TargetPort == endpoint.TargetPort {
found = true
break
}
}
if !found {
update = true
}
}
} else {
update = true
}
}
if update {
klog.Infof("%s: Ext-Endpoint update", cacheKey)
}
}
return update
}

// Update endpoint list if the list has changed
for _, sp := range m.lbCache[cacheKey].LbServicePairs {
// Check if endpoint list has changed
for _, lb := range sp.LbModelList {
if len(endpointIPs) == len(lb.Endpoints) {
nEps := 0
Expand Down

0 comments on commit bd0e3f1

Please sign in to comment.