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

standardize loadbalancer naming for GC #607

Merged
merged 1 commit into from
Jan 14, 2019
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
7 changes: 4 additions & 3 deletions pkg/loadbalancers/l7s.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func (l *L7s) List() ([]string, error) {
for _, um := range urlMaps {
if l.namer.NameBelongsToCluster(um.Name) {
nameParts := l.namer.ParseName(um.Name)
names = append(names, nameParts.LbName)
l7Name := l.namer.LoadBalancerFromLbName(nameParts.LbName)
names = append(names, l7Name)
}
}

Expand All @@ -108,11 +109,11 @@ func (l *L7s) List() ([]string, error) {

// GC garbage collects loadbalancers not in the input list.
func (l *L7s) GC(names []string) error {
glog.V(4).Infof("GC(%v)", names)
glog.V(2).Infof("GC(%v)", names)

knownLoadBalancers := sets.NewString()
for _, n := range names {
knownLoadBalancers.Insert(n)
knownLoadBalancers.Insert(l.namer.LoadBalancer(n))
}
pool, err := l.List()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/loadbalancers/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ func TestList(t *testing.T) {
t.Fatalf("pool.List() = err %v", err)
}

expected := []string{"old-l7", "test"}
expected := []string{"old-l7--uid1", "test--uid1"}

if !reflect.DeepEqual(lbNames, expected) {
t.Fatalf("pool.List() returned %+v, want %+v", lbNames, expected)
Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ func (n *Namer) LoadBalancer(key string) string {
return truncate(fmt.Sprintf("%v%v%v", scrubbedName, clusterNameDelimiter, clusterName))
}

// LoadBalancerFromLbName reconstructs the full loadbalancer name, given the
// lbName portion from NameComponents
func (n *Namer) LoadBalancerFromLbName(lbName string) string {
return fmt.Sprintf("%v%v%v", lbName, clusterNameDelimiter, n.UID())
}

// TargetProxy returns the name for target proxy given the load
// balancer name and the protocol.
func (n *Namer) TargetProxy(lbName string, protocol NamerProtocol) string {
Expand Down