diff --git a/pkg/loadbalancers/l7s.go b/pkg/loadbalancers/l7s.go index 16558b2916..6d80511085 100644 --- a/pkg/loadbalancers/l7s.go +++ b/pkg/loadbalancers/l7s.go @@ -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 @@ -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 } @@ -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)) } } diff --git a/pkg/loadbalancers/loadbalancers_test.go b/pkg/loadbalancers/loadbalancers_test.go index 09025c9da1..554aebe4f0 100644 --- a/pkg/loadbalancers/loadbalancers_test.go +++ b/pkg/loadbalancers/loadbalancers_test.go @@ -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) } } @@ -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) } } diff --git a/pkg/utils/namer/frontendnamer.go b/pkg/utils/namer/frontendnamer.go index 970b3e7331..7570a01cb3 100644 --- a/pkg/utils/namer/frontendnamer.go +++ b/pkg/utils/namer/frontendnamer.go @@ -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-- +// 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-- func newV2IngressFrontendNamer(ing *v1beta1.Ingress, clusterUID string, prefix string) IngressFrontendNamer { namer := &V2IngressFrontendNamer{ing: ing, prefix: prefix, clusterUID: clusterUID} // Initialize LbName. @@ -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.