Skip to content

Commit

Permalink
Merge pull request #90 from loxilb-io/ipam-full-fix-2
Browse files Browse the repository at this point in the history
PR - Fixed IPAM full issue in certain cases
  • Loading branch information
TrekkieCoder committed Jan 19, 2024
2 parents a5fbb08 + 3ffc0cc commit 7854e42
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
37 changes: 37 additions & 0 deletions manifest/workloads/iperf-loxilb-daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: v1
kind: Service
metadata:
name: iperf-service
annotations:
loxilb.io/lbmode: "onearm"
spec:
externalTrafficPolicy: Local
loadBalancerClass: loxilb.io/loxilb
selector:
app: iperf-app
ports:
- port: 55001
targetPort: 5001
type: LoadBalancer
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: iperf-daemonset
labels:
app: iperf-app
spec:
selector:
matchLabels:
app: iperf-app
template:
metadata:
labels:
app: iperf-app
spec:
containers:
- name: iperf
image: eyes852/ubuntu-iperf-test:0.5
command: [ "iperf", "-s"]
ports:
- containerPort: 5001
22 changes: 22 additions & 0 deletions manifest/workloads/rabbitmq-loxilb-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: rabbitmq.com/v1beta1
kind: RabbitmqCluster
metadata:
name: hello-world
spec:
replicas: 3
rabbitmq:
additionalConfig: |
log.console.level = info
channel_max = 1700
default_user= guest
default_pass = guest
default_user_tags.administrator = true
service:
type: LoadBalancer
override:
service:
spec:
loadBalancerClass: loxilb.io/loxilb
externalTrafficPolicy: Local
ports:
- port: 5672
24 changes: 10 additions & 14 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,12 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {
}
lbModelList = append(lbModelList, LbModelEnt{ingSvcPair.InRange, ingSvcPair.StaticIP, ingSvcPair.IdentIPAM, lbModel})

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
for _, client := range m.LoxiClients {
ch := make(chan error)
go func(c *api.LoxiClient, h chan error) {
var err error
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
for _, lb := range lbModelList {
if err = c.LoadBalancer().Create(ctx, &lb.LbModel); err != nil {
if !strings.Contains(err.Error(), "exist") {
Expand Down Expand Up @@ -1014,22 +1014,18 @@ func (m *Manager) getIngressSvcPairs(service *corev1.Service, addrType string) (
for _, port := range service.Spec.Ports {
proto := strings.ToLower(string(port.Protocol))
portNum := port.Port
newIP, identIPAM = ipPool.GetNewIPAddr(cacheKey, uint32(portNum), proto)
if newIP == nil {
newIP, identIPAM = ipPool.GetNewIPAddr(cacheKey, uint32(portNum), proto)
if newIP == nil {
// This is a safety code in case the service has the same port.
for _, s := range sPairs {
if s.Port == portNum && s.Protocol == proto {
continue
}
// This is a safety code in case the service has the same port.
for _, s := range sPairs {
if s.Port == portNum && s.Protocol == proto {
continue
}
klog.Errorf("failed to generate external IP. IP Pool is full")
return nil, errors.New("failed to generate external IP. IP Pool is full"), hasExtIPAllocated
}
sp = SvcPair{newIP.String(), portNum, proto, true, false, identIPAM, port}
} else {
sp = SvcPair{newIP.String(), portNum, proto, false, true, identIPAM, port}
klog.Errorf("failed to generate external IP. IP Pool is full")
return nil, errors.New("failed to generate external IP. IP Pool is full"), hasExtIPAllocated
}
sp = SvcPair{newIP.String(), portNum, proto, true, false, identIPAM, port}
sPairs = append(sPairs, sp)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ippool/ippool.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (i *IPPool) GetNewIPAddr(name string, sIdent uint32, proto string) (net.IP,
ipamIdent = tk.IPAMNoIdent
newIP, err := i.IPAlloc.AllocateNewIP(tk.IPClusterDefault, i.CIDR, ipamIdent)
if err != nil {
klog.Errorf("Allocate NewIP Failed %v:%s (%s)", sIdent, proto, err)
return nil, ipamIdent
}
return newIP, ipamIdent
Expand Down

0 comments on commit 7854e42

Please sign in to comment.