Skip to content

Commit

Permalink
Cleanup unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Satish Matti committed Nov 16, 2019
1 parent a254862 commit ac5e1d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 44 deletions.
34 changes: 8 additions & 26 deletions pkg/loadbalancers/l7s.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,16 @@ func (l *L7s) Ensure(ri *L7RuntimeInfo) (*L7, error) {
return lb, nil
}

// delete deletes a loadbalancer by name.
func (l *L7s) delete(name string, versions *features.ResourceVersions, scope meta.KeyType) error {
// delete deletes a loadbalancer by frontend namer.
func (l *L7s) delete(namer namer_util.IngressFrontendNamer, versions *features.ResourceVersions, scope meta.KeyType) error {
lb := &L7{
runtimeInfo: &L7RuntimeInfo{},
cloud: l.cloud,
namer: l.namerFactory.NamerForLbName(name),
namer: namer,
scope: scope,
}

klog.V(3).Infof("Deleting lb %v", lb.String())

if err := lb.Cleanup(versions); err != nil {
return err
}
return nil
}

// v2Delete deletes a loadbalancer frontend resources by ingress using v2 naming scheme.
func (l *L7s) v2Delete(ing *v1beta1.Ingress, versions *features.ResourceVersions, scope meta.KeyType) error {
lb := &L7{
runtimeInfo: &L7RuntimeInfo{Ingress: ing},
cloud: l.cloud,
namer: l.namerFactory.Namer(ing),
scope: scope,
}

klog.V(3).Infof("Deleting lb (using v2 naming scheme) %v", lb)
klog.V(2).Infof("Deleting loadbalancer %s", lb.String())

if err := lb.Cleanup(versions); err != nil {
return err
Expand Down Expand Up @@ -128,11 +111,11 @@ func (l *L7s) list(key *meta.Key, version meta.Version) ([]*composite.UrlMap, er
// GCv2 implements LoadBalancerPool.
func (l *L7s) GCv2(ing *v1beta1.Ingress) error {
ingKey := common.NamespacedName(ing)
klog.V(2).Infof("GC(%v)", ingKey)
if err := l.v2Delete(ing, features.VersionsFromIngress(ing), features.ScopeFromIngress(ing)); err != nil {
klog.V(2).Infof("GCv2(%v)", ingKey)
if err := l.delete(l.namerFactory.Namer(ing), features.VersionsFromIngress(ing), features.ScopeFromIngress(ing)); err != nil {
return err
}
klog.V(2).Infof("GC(%v) ok", ingKey)
klog.V(2).Infof("GCv2(%v) ok", ingKey)
return nil
}

Expand Down Expand Up @@ -196,8 +179,7 @@ func (l *L7s) gc(urlMaps []*composite.UrlMap, knownLoadBalancers sets.String, ve
continue
}

klog.V(2).Infof("GCing loadbalancer %v", l7Name)
if err := l.delete(l7Name, versions, scope); err != nil {
if err := l.delete(l.namerFactory.NamerForLbName(l7Name), versions, scope); err != nil {
errors = append(errors, fmt.Errorf("error deleting loadbalancer %q", l7Name))
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/loadbalancers/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func TestIdenticalHostnameCerts(t *testing.T) {
verifyCertAndProxyLink(expectCerts, expectCerts, j, t)
// Fetch the target proxy certs and go through in order
verifyProxyCertsInOrder(" foo.com", j, t)
j.pool.delete(common.IngressKeyFunc(lbInfo.Ingress), features.GAResourceVersions, defaultScope)
j.pool.delete(feNamer, features.GAResourceVersions, defaultScope)
}
}

Expand Down Expand Up @@ -708,7 +708,8 @@ func TestIdenticalHostnameCertsPreShared(t *testing.T) {
verifyCertAndProxyLink(expectCerts, expectCerts, j, t)
// Fetch the target proxy certs and go through in order
verifyProxyCertsInOrder(" foo.com", j, t)
j.pool.delete(common.IngressKeyFunc(lbInfo.Ingress), features.GAResourceVersions, defaultScope)
feNamer := namer_util.NewFrontendNamerFactory(j.namer, "").Namer(lbInfo.Ingress)
j.pool.delete(feNamer, features.GAResourceVersions, defaultScope)
}
}

Expand Down
23 changes: 7 additions & 16 deletions pkg/utils/namer/frontendnamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ type V2IngressFrontendNamer struct {

// newV2IngressFrontendNamer returns a v2 frontend namer for given ingress, cluster uid and prefix.
// Example:
// For Ingress - namespace/ingress, clusterUID - uid0123, prefix - k8s
// For Ingress - namespace/ingress, clusterUID - uid01234, prefix - k8s
// The resource names are -
// LoadBalancer : uid0123-namespace-ingress-cysix1wq
// HTTP Forwarding Rule : k8s2-fr-uid0123-namespace-ingress-cysix1wq
// HTTPS Forwarding Rule : k8s2-fs-uid0123-namespace-ingress-cysix1wq
// Target HTTP Proxy : k8s2-tp-uid0123-namespace-ingress-cysix1wq
// Target HTTPS Proxy : k8s2-ts-uid0123-namespace-ingress-cysix1wq
// URL Map : k8s2-um-uid0123-namespace-ingress-cysix1wq
// SSL Certificate : k8s2-cr-uid0123-<lb-hash>-<secret-hash>
// HTTP Forwarding Rule : k8s2-fr-uid01234-namespace-ingress-cysix1wq
// HTTPS Forwarding Rule : k8s2-fs-uid01234-namespace-ingress-cysix1wq
// Target HTTP Proxy : k8s2-tp-uid01234-namespace-ingress-cysix1wq
// Target HTTPS Proxy : k8s2-ts-uid01234-namespace-ingress-cysix1wq
// URL Map : k8s2-um-uid01234-namespace-ingress-cysix1wq
// SSL Certificate : k8s2-cr-uid01234-<lb-hash>-<secret-hash>
func newV2IngressFrontendNamer(ing *v1beta1.Ingress, clusterUID string, prefix string) IngressFrontendNamer {
namer := &V2IngressFrontendNamer{ing: ing, prefix: prefix, clusterUID: clusterUID}
// Initialize LbName.
Expand Down Expand Up @@ -197,15 +197,6 @@ func (vn *V2IngressFrontendNamer) LbName() string {
return vn.lbName
}

// setLbName sets loadbalancer name.
func (vn *V2IngressFrontendNamer) setLbName() {
truncFields := TrimFieldsEvenly(maximumAllowedCombinedLength, vn.ing.Namespace, vn.ing.Name)
truncNamespace := truncFields[0]
truncName := truncFields[1]
suffix := vn.suffix(vn.clusterUID, vn.ing.Namespace, vn.ing.Name)
vn.lbName = fmt.Sprintf("%s-%s-%s-%s", vn.clusterUID, truncNamespace, truncName, suffix)
}

// suffix returns hash string of length 8 of a concatenated string generated from
// uid (an 8 character hash of kube-system uid), namespace and name.
// These fields define an ingress/ load-balancer uniquely.
Expand Down

0 comments on commit ac5e1d7

Please sign in to comment.