Skip to content

Commit

Permalink
Fix bug when no fip provided in annotation the lb was created in priv…
Browse files Browse the repository at this point in the history
…ate mode and improve openstack neutron fip logic
  • Loading branch information
ccleouf66 committed Sep 15, 2023
1 parent 26fbe60 commit 7d4f5f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
11 changes: 7 additions & 4 deletions pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,14 @@ func (c *Controller) ensureIngress(ing *nwv1.Ingress) error {

if floatingIPSetting != "" {
logger.Info("try to use floating IP: ", floatingIPSetting)
address, err = c.osClient.EnsureFloatingIP(false, lb.VipPortID, floatingIPSetting, c.config.Octavia.FloatingIPNetwork, description)
if err != nil {
return fmt.Errorf("failed to use provided floating IP %s : %v", floatingIPSetting, err)
}
} else {
logger.Info("creating new floating IP")
}
address, err = c.osClient.EnsureFloatingIP(false, lb.VipPortID, floatingIPSetting, c.config.Octavia.FloatingIPNetwork, description)
if err != nil {
return fmt.Errorf("failed to use provided floating IP %s : %v", floatingIPSetting, err)
}
logger.Info("floating IP ", address, " configured")
}

// Update ingress status
Expand Down
37 changes: 16 additions & 21 deletions pkg/ingress/controller/openstack/neutron.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,18 @@ func (os *OpenStack) EnsureFloatingIP(needDelete bool, portID string, existingfl

var fip *floatingips.FloatingIP

// check if provided fip is available
if existingfloatingIP != "" {
if existingfloatingIP == "" {
if len(fips) == 1 {
fip = &fips[0]
} else {
fip, err = os.createFloatingIP(portID, floatingIPNetwork, description)
if err != nil {
return "", err
}
}
} else {
// if user provide FIP
// try to it
// check if provided fip is available
opts := floatingips.ListOpts{
FloatingIP: existingfloatingIP,
FloatingNetworkID: floatingIPNetwork,
Expand All @@ -146,27 +154,14 @@ func (os *OpenStack) EnsureFloatingIP(needDelete bool, portID string, existingfl
if osFips[0].PortID != "" {
return "", fmt.Errorf("floating IP %s already used by port %s", osFips[0].FloatingIP, osFips[0].PortID)
}
fip = &osFips[0]
}

// if port don't have fip
if len(fips) == 0 {
// if user provided fip to use
if fip != nil {
// attach fip to lb vip
fip, err = os.associateFloatingIP(fip, portID, description)
if err != nil {
return "", err
}
} else {
fip, err = os.createFloatingIP(portID, floatingIPNetwork, description)
// if port don't have fip
if len(fips) == 0 {
fip, err = os.associateFloatingIP(&osFips[0], portID, description)
if err != nil {
return "", err
}
}
} else {
// if port exist but the fip binded to it's not the one provided by user
if fip.FloatingIP != fips[0].FloatingIP {
} else if osFips[0].FloatingIP != fips[0].FloatingIP {
// disassociate old fip : if update fip without disassociate
// Openstack retrun http 409 error
// "Cannot associate floating IP with port using fixed
Expand All @@ -177,7 +172,7 @@ func (os *OpenStack) EnsureFloatingIP(needDelete bool, portID string, existingfl
return "", err
}
// associate new fip
fip, err = os.associateFloatingIP(fip, portID, description)
fip, err = os.associateFloatingIP(&osFips[0], portID, description)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 7d4f5f0

Please sign in to comment.