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

Fix setting the merged service to servicesByHostname #50691

Merged
merged 4 commits into from
Apr 29, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion pilot/pkg/model/sidecar.go
Expand Up @@ -980,7 +980,8 @@ func (sc *SidecarScope) appendSidecarServices(servicesAdded map[host.Name]sideca
// Update index as well, so that future reads will merge into the new service
foundSvc.svc = copied
servicesAdded[foundSvc.svc.Hostname] = foundSvc
sc.servicesByHostname[s.Hostname] = s
// update the existing service in the map to the merged one
sc.servicesByHostname[s.Hostname] = copied
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems really subtle; should we add a comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test to gurantee. Yes, actually copied is the merged Service

}
}

Expand Down
7 changes: 7 additions & 0 deletions pilot/pkg/model/sidecar_test.go
Expand Up @@ -2534,6 +2534,13 @@ func TestCreateSidecarScope(t *testing.T) {
} else if len(ports) > 0 && !portsMatched {
t.Errorf("Expected service %v found in SidecarScope but ports not merged correctly. want: %v, got: %v", s1.Hostname, ports, s1.Ports)
}

// validate service is also in sidecarScope.serviceByHostname
if s2, ok := sidecarScope.servicesByHostname[s1.Hostname]; !ok {
t.Errorf("Expected service %v should also in servicesByHostname", s1.Hostname)
} else if s1 != s2 {
t.Errorf("Expected service %v in SidecarScope.Services should equal to that in SidecarScope.servicesByHostname", s1.Hostname)
}
}

for _, s1 := range tt.expectedServices {
Expand Down