Skip to content

Commit

Permalink
Merge pull request #24 from expektorans/fix/dont-lose-ips
Browse files Browse the repository at this point in the history
Fix/dont lose ips
  • Loading branch information
horazont authored Feb 12, 2021
2 parents d4ebb0e + 15bfa1f commit b682256
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/controller/model_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (g *PodLoadBalancerModelGenerator) GenerateModel(portAssignment map[string]

ingress, ok := ingressMap[portID]
if !ok {
klog.Infof("Calling GetInternalAddress for portID=%q, serviceKey=%q", portID, serviceKey)
ingressIP, err := g.l3portmanager.GetInternalAddress(portID)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/port_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (c *PortMapperImpl) createNewL3Port() (string, error) {
if err != nil {
return "", err
}
klog.Infof("created new port with portID=%v", portID)
c.emplaceL3Port(portID)
return portID, nil
}
Expand Down Expand Up @@ -182,6 +183,7 @@ func (c *PortMapperImpl) MapService(svc *corev1.Service) error {
// if no existing port can fit the bill, we move on to create a new
// port
portID, err = c.createNewL3Port()
klog.Infof("Created new port with portID=%v", portID)
if err != nil {
// if that fails too, we simply cannot map the service.
return err
Expand All @@ -195,6 +197,7 @@ func (c *PortMapperImpl) MapService(svc *corev1.Service) error {

if hasExistingService {
// we have to unmap the existing service first
klog.Infof("Trying to unmap service %q", id)
err = c.UnmapService(id)
if err != nil {
panic(fmt.Sprintf("UnmapService during MapService failed. Invariants are now broken."))
Expand All @@ -203,7 +206,9 @@ func (c *PortMapperImpl) MapService(svc *corev1.Service) error {

c.services[key] = svcModel
l3port := c.l3ports[portID]
klog.Infof("Lookup l3port[%v]=%v", portID, l3port)
for _, port := range svcModel.Ports {
klog.Infof("Allocating port %v to service %v", port, key)
l3port.Allocations[port.Port] = key
}

Expand Down
22 changes: 19 additions & 3 deletions internal/openstack/port_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ const (
)

var (
ErrFloatingIPMissing = errors.New("Expected floating IP was not found")
ErrFixedIPMissing = errors.New("Port has no IP address assigned")
ErrFloatingIPMissing = errors.New("Expected floating IP was not found")
ErrFixedIPMissing = errors.New("Port has no IP address assigned")
ErrPortIsNil = errors.New("Port is nil")
ErrNoFloatingIPCreated = errors.New("No floating IP was created by OpenStack")
)

// We need options which are not included in the default gophercloud struct
Expand Down Expand Up @@ -164,6 +166,7 @@ func (pm *OpenStackL3PortManager) ProvisionPort() (string, error) {
}

cleanupPort := func() {
klog.Infof("Deleting port %v", port.ID)
deleteErr := portsv2.Delete(pm.client, port.ID).ExtractErr()
if deleteErr != nil {
klog.Warningf(
Expand All @@ -185,8 +188,9 @@ func (pm *OpenStackL3PortManager) ProvisionPort() (string, error) {
if pm.cfg.UseFloatingIPs {
err = pm.provisionFloatingIP(port.ID)
if err != nil {
klog.Warningf("Couldn't provide floating ip for port=%v: %s", port.ID, err)
cleanupPort()
return "", nil
return "", ErrNoFloatingIPCreated
}
}

Expand Down Expand Up @@ -220,6 +224,7 @@ func (pm *OpenStackL3PortManager) deleteUnusedFloatingIPs() error {
// even in case of an error, we can at least try to delete the fips we
// already gathered
for _, fipID := range toDelete {
klog.Infof("Trying to delete floating ip %q", fipID)
deleteErr := floatingipsv2.Delete(pm.client, fipID).ExtractErr()
if deleteErr != nil {
klog.Warningf(
Expand All @@ -234,6 +239,7 @@ func (pm *OpenStackL3PortManager) deleteUnusedFloatingIPs() error {

func (pm *OpenStackL3PortManager) CleanUnusedPorts(usedPorts []string) error {
ports, err := pm.cache.GetPorts()
klog.Infof("Used ports=%q", usedPorts)
if err != nil {
return err
}
Expand All @@ -249,6 +255,7 @@ func (pm *OpenStackL3PortManager) CleanUnusedPorts(usedPorts []string) error {
continue
}

klog.Infof("Trying to delete port %q", port.ID)
// port not in use, issue deletion
err := portsv2.Delete(pm.client, port.ID).ExtractErr()
if err != nil {
Expand Down Expand Up @@ -285,6 +292,11 @@ func (pm *OpenStackL3PortManager) GetExternalAddress(portID string) (string, str
return "", "", err
}

if port == nil {
klog.Warningf("Port with portID %q is nil", portID)
return "", "", ErrPortIsNil
}

if pm.cfg.UseFloatingIPs {
if fip == nil {
return "", "", ErrFloatingIPMissing
Expand All @@ -305,6 +317,10 @@ func (pm *OpenStackL3PortManager) GetInternalAddress(portID string) (string, err
if err != nil {
return "", err
}
if port == nil {
klog.Warningf("Port with portID %q is nil", portID)
return "", ErrPortIsNil
}

if len(port.FixedIPs) == 0 {
return "", ErrFixedIPMissing
Expand Down

0 comments on commit b682256

Please sign in to comment.