Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - Fixed IPAM full issue in certain cases #90

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading