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

Use kube-system UID instead of its hash to compute resource suffix #967

Merged
merged 1 commit into from
Dec 6, 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
24 changes: 11 additions & 13 deletions pkg/utils/namer/frontendnamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type V2IngressFrontendNamer struct {
clusterUID string
}

// newV2IngressFrontendNamer returns a v2 frontend namer for given ingress, cluster uid and prefix.
// newV2IngressFrontendNamer returns a v2 frontend namer for given ingress, kube-system uid and prefix.
// Example:
// For Ingress - namespace/ingress, clusterUID - uid01234, prefix - k8s
// The resource names are -
Expand All @@ -132,13 +132,14 @@ type V2IngressFrontendNamer struct {
// 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 {
func newV2IngressFrontendNamer(ing *v1beta1.Ingress, kubeSystemUID string, prefix string) IngressFrontendNamer {
clusterUID := common.ContentHash(kubeSystemUID, clusterUIDLength)
namer := &V2IngressFrontendNamer{ing: ing, prefix: prefix, clusterUID: clusterUID}
// Initialize LbName.
truncFields := TrimFieldsEvenly(maximumAllowedCombinedLength, ing.Namespace, ing.Name)
truncNamespace := truncFields[0]
truncName := truncFields[1]
suffix := namer.suffix(clusterUID, ing.Namespace, ing.Name)
suffix := namer.suffix(kubeSystemUID, ing.Namespace, ing.Name)
namer.lbName = fmt.Sprintf("%s-%s-%s-%s", clusterUID, truncNamespace, truncName, suffix)
return namer
}
Expand Down Expand Up @@ -198,8 +199,7 @@ func (vn *V2IngressFrontendNamer) LbName() string {
}

// 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.
// uid, namespace and name. These fields in combination define an ingress/load-balancer uniquely.
func (vn *V2IngressFrontendNamer) suffix(uid, namespace, name string) string {
lbString := strings.Join([]string{uid, namespace, name}, ";")
return common.ContentHash(lbString, 8)
Expand All @@ -213,16 +213,14 @@ func (vn *V2IngressFrontendNamer) lbNameToHash() string {
// FrontendNamerFactory implements IngressFrontendNamerFactory.
type FrontendNamerFactory struct {
namer *Namer
// clusterUID is an 8 character hash of kube-system UID that is included
// in resource names.
// kubeSystemUID is the UID of kube-system namespace which is unique for a k8s cluster.
// Note that this is used only for V2IngressFrontendNamer.
clusterUID string
kubeSystemUID string
}

// NewFrontendNamerFactory returns IngressFrontendNamerFactory given a v1 namer and uid.
func NewFrontendNamerFactory(namer *Namer, uid types.UID) IngressFrontendNamerFactory {
clusterUID := common.ContentHash(string(uid), clusterUIDLength)
return &FrontendNamerFactory{namer: namer, clusterUID: clusterUID}
// NewFrontendNamerFactory returns IngressFrontendNamerFactory given a v1 namer and kube-system uid.
func NewFrontendNamerFactory(namer *Namer, kubeSystemUID types.UID) IngressFrontendNamerFactory {
return &FrontendNamerFactory{namer: namer, kubeSystemUID: string(kubeSystemUID)}
}

// Namer implements IngressFrontendNamerFactory.
Expand All @@ -232,7 +230,7 @@ func (rn *FrontendNamerFactory) Namer(ing *v1beta1.Ingress) IngressFrontendNamer
case V1NamingScheme:
return newV1IngressFrontendNamer(ing, rn.namer)
case V2NamingScheme:
return newV2IngressFrontendNamer(ing, rn.clusterUID, rn.namer.prefix)
return newV2IngressFrontendNamer(ing, rn.kubeSystemUID, rn.namer.prefix)
default:
klog.Errorf("Unexpected frontend naming scheme %s", namingScheme)
return newV1IngressFrontendNamer(ing, rn.namer)
Expand Down
100 changes: 50 additions & 50 deletions pkg/utils/namer/frontendnamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

const (
clusterUID = "uid1"
kubeSystemUID = "ksuid123"
kubeSystemUID = "kubesystem-uid1"
)

func newIngress(namespace, name string) *v1beta1.Ingress {
Expand Down Expand Up @@ -261,85 +261,85 @@ func TestV2IngressFrontendNamer(t *testing.T) {
"simple case",
"namespace",
"name",
"ksuid123-namespace-name-wddys49o",
"%s2-tp-ksuid123-namespace-name-wddys49o",
"%s2-ts-ksuid123-namespace-name-wddys49o",
"%s2-cr-ksuid123-lb75yy4dn9xa8ib0-%s",
"%s2-fr-ksuid123-namespace-name-wddys49o",
"%s2-fs-ksuid123-namespace-name-wddys49o",
"%s2-um-ksuid123-namespace-name-wddys49o",
"7kpbhpki-namespace-name-uhmwf5xi",
"%s2-tp-7kpbhpki-namespace-name-uhmwf5xi",
"%s2-ts-7kpbhpki-namespace-name-uhmwf5xi",
"%s2-cr-7kpbhpki-fvix6gj3ge1emsdj-%s",
"%s2-fr-7kpbhpki-namespace-name-uhmwf5xi",
"%s2-fs-7kpbhpki-namespace-name-uhmwf5xi",
"%s2-um-7kpbhpki-namespace-name-uhmwf5xi",
},
{
"62 characters",
longString[:23],
longString[:24],
"ksuid123-012345678901234567-012345678901234567-sce8socf",
"%s2-tp-ksuid123-012345678901234567-012345678901234567-sce8socf",
"%s2-ts-ksuid123-012345678901234567-012345678901234567-sce8socf",
"%s2-cr-ksuid123-dlz1pf382qzmdac9-%s",
"%s2-fr-ksuid123-012345678901234567-012345678901234567-sce8socf",
"%s2-fs-ksuid123-012345678901234567-012345678901234567-sce8socf",
"%s2-um-ksuid123-012345678901234567-012345678901234567-sce8socf",
"7kpbhpki-012345678901234567-012345678901234567-hg17g9tx",
"%s2-tp-7kpbhpki-012345678901234567-012345678901234567-hg17g9tx",
"%s2-ts-7kpbhpki-012345678901234567-012345678901234567-hg17g9tx",
"%s2-cr-7kpbhpki-ktiggo5yie4uh72b-%s",
"%s2-fr-7kpbhpki-012345678901234567-012345678901234567-hg17g9tx",
"%s2-fs-7kpbhpki-012345678901234567-012345678901234567-hg17g9tx",
"%s2-um-7kpbhpki-012345678901234567-012345678901234567-hg17g9tx",
},
{
"63 characters",
longString[:24],
longString[:24],
"ksuid123-012345678901234567-012345678901234567-tabdkrlv",
"%s2-tp-ksuid123-012345678901234567-012345678901234567-tabdkrlv",
"%s2-ts-ksuid123-012345678901234567-012345678901234567-tabdkrlv",
"%s2-cr-ksuid123-8ohtur3hfgw0qe3f-%s",
"%s2-fr-ksuid123-012345678901234567-012345678901234567-tabdkrlv",
"%s2-fs-ksuid123-012345678901234567-012345678901234567-tabdkrlv",
"%s2-um-ksuid123-012345678901234567-012345678901234567-tabdkrlv",
"7kpbhpki-012345678901234567-012345678901234567-o0dahbae",
"%s2-tp-7kpbhpki-012345678901234567-012345678901234567-o0dahbae",
"%s2-ts-7kpbhpki-012345678901234567-012345678901234567-o0dahbae",
"%s2-cr-7kpbhpki-kk38dnbt6k8zrg76-%s",
"%s2-fr-7kpbhpki-012345678901234567-012345678901234567-o0dahbae",
"%s2-fs-7kpbhpki-012345678901234567-012345678901234567-o0dahbae",
"%s2-um-7kpbhpki-012345678901234567-012345678901234567-o0dahbae",
},
{
"64 characters",
longString[:24],
longString[:25],
"ksuid123-012345678901234567-012345678901234567-dhfwuws7",
"%s2-tp-ksuid123-012345678901234567-012345678901234567-dhfwuws7",
"%s2-ts-ksuid123-012345678901234567-012345678901234567-dhfwuws7",
"%s2-cr-ksuid123-1vm2cunkgqy1exss-%s",
"%s2-fr-ksuid123-012345678901234567-012345678901234567-dhfwuws7",
"%s2-fs-ksuid123-012345678901234567-012345678901234567-dhfwuws7",
"%s2-um-ksuid123-012345678901234567-012345678901234567-dhfwuws7",
"7kpbhpki-012345678901234567-012345678901234567-sxo4pxda",
"%s2-tp-7kpbhpki-012345678901234567-012345678901234567-sxo4pxda",
"%s2-ts-7kpbhpki-012345678901234567-012345678901234567-sxo4pxda",
"%s2-cr-7kpbhpki-n2b7ixc007o1ddma-%s",
"%s2-fr-7kpbhpki-012345678901234567-012345678901234567-sxo4pxda",
"%s2-fs-7kpbhpki-012345678901234567-012345678901234567-sxo4pxda",
"%s2-um-7kpbhpki-012345678901234567-012345678901234567-sxo4pxda",
},
{
"long namespace",
longString,
"0",
"ksuid123-012345678901234567890123456789012345--4mg0wxbi",
"%s2-tp-ksuid123-012345678901234567890123456789012345--4mg0wxbi",
"%s2-ts-ksuid123-012345678901234567890123456789012345--4mg0wxbi",
"%s2-cr-ksuid123-wfasfag894xpvmnr-%s",
"%s2-fr-ksuid123-012345678901234567890123456789012345--4mg0wxbi",
"%s2-fs-ksuid123-012345678901234567890123456789012345--4mg0wxbi",
"%s2-um-ksuid123-012345678901234567890123456789012345--4mg0wxbi",
"7kpbhpki-012345678901234567890123456789012345--v8ajgbg3",
"%s2-tp-7kpbhpki-012345678901234567890123456789012345--v8ajgbg3",
"%s2-ts-7kpbhpki-012345678901234567890123456789012345--v8ajgbg3",
"%s2-cr-7kpbhpki-m6a592dazogk94ra-%s",
"%s2-fr-7kpbhpki-012345678901234567890123456789012345--v8ajgbg3",
"%s2-fs-7kpbhpki-012345678901234567890123456789012345--v8ajgbg3",
"%s2-um-7kpbhpki-012345678901234567890123456789012345--v8ajgbg3",
},
{
"long name",
"0",
longString,
"ksuid123-0-01234567890123456789012345678901234-mebui9t8",
"%s2-tp-ksuid123-0-01234567890123456789012345678901234-mebui9t8",
"%s2-ts-ksuid123-0-01234567890123456789012345678901234-mebui9t8",
"%s2-cr-ksuid123-50ba1vszcf9aeh73-%s",
"%s2-fr-ksuid123-0-01234567890123456789012345678901234-mebui9t8",
"%s2-fs-ksuid123-0-01234567890123456789012345678901234-mebui9t8",
"%s2-um-ksuid123-0-01234567890123456789012345678901234-mebui9t8",
"7kpbhpki-0-01234567890123456789012345678901234-fyhus2f6",
"%s2-tp-7kpbhpki-0-01234567890123456789012345678901234-fyhus2f6",
"%s2-ts-7kpbhpki-0-01234567890123456789012345678901234-fyhus2f6",
"%s2-cr-7kpbhpki-a33x986k79kbu0me-%s",
"%s2-fr-7kpbhpki-0-01234567890123456789012345678901234-fyhus2f6",
"%s2-fs-7kpbhpki-0-01234567890123456789012345678901234-fyhus2f6",
"%s2-um-7kpbhpki-0-01234567890123456789012345678901234-fyhus2f6",
},
{
"long name and namespace",
longString,
longString,
"ksuid123-012345678901234567-012345678901234567-4mwbp6m5",
"%s2-tp-ksuid123-012345678901234567-012345678901234567-4mwbp6m5",
"%s2-ts-ksuid123-012345678901234567-012345678901234567-4mwbp6m5",
"%s2-cr-ksuid123-7trbunxyryt39g1b-%s",
"%s2-fr-ksuid123-012345678901234567-012345678901234567-4mwbp6m5",
"%s2-fs-ksuid123-012345678901234567-012345678901234567-4mwbp6m5",
"%s2-um-ksuid123-012345678901234567-012345678901234567-4mwbp6m5",
"7kpbhpki-012345678901234567-012345678901234567-69z4wrm0",
"%s2-tp-7kpbhpki-012345678901234567-012345678901234567-69z4wrm0",
"%s2-ts-7kpbhpki-012345678901234567-012345678901234567-69z4wrm0",
"%s2-cr-7kpbhpki-5pu4c55s4c47rr9e-%s",
"%s2-fr-7kpbhpki-012345678901234567-012345678901234567-69z4wrm0",
"%s2-fs-7kpbhpki-012345678901234567-012345678901234567-69z4wrm0",
"%s2-um-7kpbhpki-012345678901234567-012345678901234567-69z4wrm0",
},
}
for _, prefix := range []string{"k8s", "xyz"} {
Expand Down