Skip to content

Commit

Permalink
standardize loadbalancer naming for GC
Browse files Browse the repository at this point in the history
  • Loading branch information
agau4779 committed Jan 14, 2019
1 parent 99946cd commit c74db67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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

0 comments on commit c74db67

Please sign in to comment.