-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For a while now (potentially since ever), ch-k8s-lbaas has been known for losing floating IPs. We were so far unable to track it down---the logs were always inconclusive and it wasn't fully clear where the issue might come from. As "cache invalidation" is one of the two hard problems in computer science (next to naming things and off-by-one errors), it seems most sensible to rip out the port cache. With the typical cluster size, it should not be necessary to have a cache. In addition, using a cache is in direct contradiction to acting on the current state (even though API calls also always return stale data, but at least it's less stale than your average cache), which we normally want to do in the Kubernetes world. So let's try this, for a change.
- Loading branch information
Showing
3 changed files
with
108 additions
and
174 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright 2020 CLOUD&HEAT Technologies GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package openstack | ||
|
||
import ( | ||
"github.com/gophercloud/gophercloud" | ||
floatingipsv2 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" | ||
portsv2 "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" | ||
"github.com/gophercloud/gophercloud/pagination" | ||
|
||
"k8s.io/klog" | ||
) | ||
|
||
type CachedPort struct { | ||
Port portsv2.Port | ||
FloatingIP *floatingipsv2.FloatingIP | ||
} | ||
|
||
type UncachedClient struct { | ||
client *gophercloud.ServiceClient | ||
tag string | ||
useFloatingIPs bool | ||
} | ||
|
||
type PortClient interface { | ||
GetPorts() ([]*portsv2.Port, error) | ||
GetPortByID(ID string) (*portsv2.Port, *floatingipsv2.FloatingIP, error) | ||
} | ||
|
||
func NewPortClient(networkingclient *gophercloud.ServiceClient, tag string, useFloatingIPs bool) *UncachedClient { | ||
return &UncachedClient{ | ||
client: networkingclient, | ||
tag: tag, | ||
useFloatingIPs: useFloatingIPs, | ||
} | ||
} | ||
|
||
func (pc *UncachedClient) GetPorts() (ports []*portsv2.Port, err error) { | ||
err = portsv2.List( | ||
pc.client, | ||
portsv2.ListOpts{Tags: pc.tag}, | ||
).EachPage(func(page pagination.Page) (bool, error) { | ||
fetched_ports, err := portsv2.ExtractPorts(page) | ||
if err != nil { | ||
return false, err | ||
} | ||
for _, found_port := range fetched_ports { | ||
ports = append(ports, &found_port) | ||
} | ||
return true, nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ports, err | ||
} | ||
|
||
func (pc *UncachedClient) GetPortByID(ID string) (port *portsv2.Port, fip *floatingipsv2.FloatingIP, err error) { | ||
port, err = portsv2.Get( | ||
pc.client, | ||
ID, | ||
).Extract() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
if pc.useFloatingIPs { | ||
err = floatingipsv2.List( | ||
pc.client, | ||
floatingipsv2.ListOpts{Tags: pc.tag, PortID: ID}, | ||
).EachPage(func(page pagination.Page) (bool, error) { | ||
fips, err := floatingipsv2.ExtractFloatingIPs(page) | ||
if err != nil { | ||
return false, err | ||
} | ||
for _, found_fip := range fips { | ||
if fip != nil { | ||
// TODO: warn here?! | ||
klog.Warningf("Found multiple floating IPs for port %s (%s and %s at least)", ID, fip.ID, found_fip.ID) | ||
} | ||
fip = &found_fip | ||
} | ||
return true, nil | ||
}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
} | ||
return port, fip, nil | ||
} |