Skip to content

Commit

Permalink
Fix setting the merged service to servicesByHostname (#50691)
Browse files Browse the repository at this point in the history
* Fix services in SidecarScope.servicesByHostname not equal to  SidecarScope.services

* fix lint

* update comment

* rm blank line
  • Loading branch information
hzxuzhonghu committed Apr 29, 2024
1 parent 807f97b commit 81284e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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
}
}

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

0 comments on commit 81284e3

Please sign in to comment.