Skip to content

Commit

Permalink
Merge pull request #154 from backguynn/main
Browse files Browse the repository at this point in the history
add debug logs
  • Loading branch information
backguynn committed Jul 5, 2024
2 parents 3112a76 + a5ebc3a commit dd80f61
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/agent/manager/gatewayapi/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
minRetryDelay = 2 * time.Second
maxRetryDelay = 120 * time.Second
defaultWorkers = 4
contextTimeout = 5 * time.Second
contextTimeout = 30 * time.Second
implementation = "kube-loxilb"
finalizer = "loxilb.io"
)
2 changes: 1 addition & 1 deletion pkg/agent/manager/gatewayapi/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewGatewayManager(
gatewayLister: gatewayInformer.Lister(),
gatewayListerSynced: gatewayInformer.Informer().HasSynced,

queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "gatewayClass"),
queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "gateway"),
}

manager.gatewayInformer.Informer().AddEventHandler(
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/manager/gatewayapi/tcproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewTCPRouteManager(
tcpRouteLister: tcpRouteInformer.Lister(),
tcpRouteListerSynced: tcpRouteInformer.Informer().HasSynced,

queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "gatewayClass"),
queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "tcpRoute"),
}

manager.tcpRouteInformer.Informer().AddEventHandler(
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/manager/gatewayapi/udproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewUDPRouteManager(
udpRouteLister: udpRouteInformer.Lister(),
udpRouteListerSynced: udpRouteInformer.Informer().HasSynced,

queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "gatewayClass"),
queue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(minRetryDelay, maxRetryDelay), "udpRoute"),
}

manager.udpRouteInformer.Informer().AddEventHandler(
Expand Down
45 changes: 27 additions & 18 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,21 +1373,25 @@ func (m *Manager) getIngressSvcPairs(service *corev1.Service, addrType string, l

// k8s service has ingress IP already
if len(inSPairs) >= 1 {
klog.V(4).Infof("getIngressSvcPairs: service %s has servicePairs: %v", cacheKey, inSPairs)
klog.V(4).Infof("getIngressSvcPairs: service %s has externalIP: %v", cacheKey, service.Status.LoadBalancer.Ingress)
checkSvcPortLoop:
for _, inSPair := range inSPairs {

hasExtIPAllocated = true
for _, sp := range lbCacheEntry.LbServicePairs {
if GenSPKey(inSPair.IPString, uint16(inSPair.Port), inSPair.Protocol) == GenSPKey(sp.ExternalIP, sp.Port, sp.Protocol) {
sp := SvcPair{sp.ExternalIP, int32(sp.Port), sp.Protocol, sp.InRange, sp.StaticIP, sp.IdentIPAM, false, inSPair.K8sSvcPort}
sPairs = append(sPairs, sp)
oldsp := SvcPair{sp.ExternalIP, int32(sp.Port), sp.Protocol, sp.InRange, sp.StaticIP, sp.IdentIPAM, false, inSPair.K8sSvcPort}
sPairs = append(sPairs, oldsp)
klog.V(4).Infof("getIngressSvcPairs: LB cache %s already has servicePairs: %v", cacheKey, sp)
continue checkSvcPortLoop
}
}

inRange, _, identStr := ipPool.CheckAndReserveIP(inSPair.IPString, cacheKey, uint32(inSPair.Port), inSPair.Protocol)
sp := SvcPair{inSPair.IPString, inSPair.Port, inSPair.Protocol, inRange, true, identStr, true, inSPair.K8sSvcPort}
sPairs = append(sPairs, sp)
newsp := SvcPair{inSPair.IPString, inSPair.Port, inSPair.Protocol, inRange, true, identStr, true, inSPair.K8sSvcPort}
klog.V(4).Infof("getIngressSvcPairs: LB cache %s is added servicePairs: %v", cacheKey, newsp)
sPairs = append(sPairs, newsp)
}
}

Expand All @@ -1396,31 +1400,35 @@ func (m *Manager) getIngressSvcPairs(service *corev1.Service, addrType string, l

// If hasExtIPAllocated is false, that means k8s service has no ingress IP
if !hasExtIPAllocated {
var sp SvcPair
klog.V(4).Infof("getIngressSvcPairs: service %s has no externalIP: %v", cacheKey, service.Status.LoadBalancer.Ingress)
checkServicePortLoop:
for _, port := range service.Spec.Ports {
proto := strings.ToLower(string(port.Protocol))
portNum := port.Port

for _, sp := range lbCacheEntry.LbServicePairs {
if sp.Port == uint16(portNum) && proto == sp.Protocol {
sp := SvcPair{sp.ExternalIP, int32(sp.Port), sp.Protocol, sp.InRange, sp.StaticIP, sp.IdentIPAM, false, port}
sPairs = append(sPairs, sp)
oldsp := SvcPair{sp.ExternalIP, int32(sp.Port), sp.Protocol, sp.InRange, sp.StaticIP, sp.IdentIPAM, false, port}
sPairs = append(sPairs, oldsp)
klog.V(4).Infof("getIngressSvcPairs: LB cache %s already has servicePairs: %v", cacheKey, sp)
continue checkServicePortLoop
}
}

newIP, identIPAM = ipPool.GetNewIPAddr(cacheKey, uint32(portNum), proto)
if newIP == nil {
klog.Errorf("failed to generate external IP. IP Pool is full")
errMsg := fmt.Sprintf("failed to generate external IP. %s:%d:%s already used for %s", cacheKey, portNum, proto, identIPAM)
klog.Errorf(errMsg)
klog.Exit("kube-loxilb cant run optimally anymore")
return nil, errors.New("failed to generate external IP. IP Pool is full"), hasExtIPAllocated
return nil, errors.New(errMsg), hasExtIPAllocated
}
sp = SvcPair{newIP.String(), portNum, proto, true, false, identIPAM, true, port}
sPairs = append(sPairs, sp)

klog.V(4).Infof("getIngressSvcPairs: service %s is generated new externalIP: %s", cacheKey, newIP.String())

newsp := SvcPair{newIP.String(), portNum, proto, true, false, identIPAM, true, port}
sPairs = append(sPairs, newsp)
}
}
//klog.Infof("Spairs: %v", sPairs)
return sPairs, nil, hasExtIPAllocated
}

Expand Down Expand Up @@ -1493,8 +1501,8 @@ func (m *Manager) getIngressSecSvcPairs(service *corev1.Service, numSecondary in

for _, sp := range lbCacheEntry.LbServicePairs {
if sp.Port == uint16(portNum) && proto == sp.Protocol {
sp := SvcPair{sp.ExternalIP, int32(sp.Port), sp.Protocol, sp.InRange, sp.StaticIP, sp.IdentIPAM, false, port}
sPairs = append(sPairs, sp)
oldsp := SvcPair{sp.ExternalIP, int32(sp.Port), sp.Protocol, sp.InRange, sp.StaticIP, sp.IdentIPAM, false, port}
sPairs = append(sPairs, oldsp)
continue checkServicePortLoop
}
}
Expand All @@ -1505,12 +1513,13 @@ func (m *Manager) getIngressSecSvcPairs(service *corev1.Service, numSecondary in
rpool := sipPools[j]
rpool.ReturnIPAddr(sPairs[j].IPString, sPairs[j].IdentIPAM)
}
klog.Errorf("failed to generate external secondary IP. IP Pool is full")
errMsg := fmt.Sprintf("failed to generate secondary external IP. %s:%d:%s already used for %s", cacheKey, portNum, proto, identIPAM)
klog.Errorf(errMsg)
klog.Exit("kube-loxilb cant run optimally anymore")
return nil, errors.New("failed to generate external secondary IP. IP Pool is full")
return nil, errors.New(errMsg)
}
sp := SvcPair{newIP.String(), portNum, proto, true, false, identIPAM, true, port}
sPairs = append(sPairs, sp)
newsp := SvcPair{newIP.String(), portNum, proto, true, false, identIPAM, true, port}
sPairs = append(sPairs, newsp)
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/api/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type LoadBalancerService struct {
ProbeResp string `json:"proberesp"`
ProbeRetries int32 `json:"probeRetries,omitempty"`
ProbeTimeout uint32 `json:"probeTimeout,omitempty"`
Security int32 `json:"security,omitempty"`
Name string `json:"name,omitempty"`
Oper LbOP `json:"oper,omitempty"`
}
Expand Down

0 comments on commit dd80f61

Please sign in to comment.