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

[Cherry-pick #2054 to 1.22] Change diffBackends for NEG to not compare the API versions. #2055

Closed
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: 19 additions & 5 deletions pkg/backends/neg_linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ func diffBackends(old, new []*composite.Backend) *backendDiff {

oldMap := map[string]*composite.Backend{}
for _, be := range old {
d.old.Insert(be.Group)
oldMap[be.Group] = be
beGroup := relativeResourceNameWithDefault(be.Group)
d.old.Insert(beGroup)
oldMap[beGroup] = be
}
for _, be := range new {
d.new.Insert(be.Group)
beGroup := relativeResourceNameWithDefault(be.Group)
d.new.Insert(beGroup)

if oldBe, ok := oldMap[be.Group]; ok {
if oldBe, ok := oldMap[beGroup]; ok {
// Note: if you are comparing a value that has a non-zero default
// value (e.g. CapacityScaler is 1.0), you will need to set that
// value when creating a new Backend to avoid a false positive when
Expand All @@ -183,7 +185,7 @@ func diffBackends(old, new []*composite.Backend) *backendDiff {
changed = changed || oldBe.MaxRatePerEndpoint != be.MaxRatePerEndpoint
changed = changed || oldBe.CapacityScaler != be.CapacityScaler
if changed {
d.changed.Insert(be.Group)
d.changed.Insert(beGroup)
}
}
}
Expand Down Expand Up @@ -264,3 +266,15 @@ func getNegUrlFromSvcneg(key string, zone string, svcNegLister cache.Indexer) (s
}
return "", false
}

// relativeResourceNameWithDefault will attempt to return a RelativeResourceName
// for the provided `selfLink`. In case of a faiure, it will return the
// `selfLink` itself.
func relativeResourceNameWithDefault(selfLink string) string {
result, err := utils.RelativeResourceName(selfLink)
if err != nil {
klog.Warningf("Unable to parse resource name from selfLink %q", selfLink)
return selfLink
}
return result
}
12 changes: 12 additions & 0 deletions pkg/backends/neg_linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ func TestDiffBackends(t *testing.T) {
new: []*composite.Backend{{Group: "b"}, {Group: "a"}},
isEqual: true,
},
{
name: "same but different api version",
old: []*composite.Backend{
{Group: "https://www.googleapis.com/compute/beta/projects/project-name/zones/us-central1-c/networkEndpointGroups/k8s1-neg-name-1"},
{Group: "https://www.googleapis.com/compute/v1/projects/project-name/zones/us-central1-c/networkEndpointGroups/k8s1-neg-name-2"},
},
new: []*composite.Backend{
{Group: "https://www.googleapis.com/compute/v1/projects/project-name/zones/us-central1-c/networkEndpointGroups/k8s1-neg-name-1"},
{Group: "https://www.googleapis.com/compute/beta/projects/project-name/zones/us-central1-c/networkEndpointGroups/k8s1-neg-name-2"},
},
isEqual: true,
},
{
name: "add backend",
old: []*composite.Backend{{Group: "a"}},
Expand Down