Skip to content

Commit

Permalink
Fix service entry merge
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjohn committed Apr 26, 2024
1 parent 676ba0e commit d17ed67
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pilot/pkg/model/endpointshards.go
Expand Up @@ -23,6 +23,7 @@ import (
"istio.io/istio/pilot/pkg/serviceregistry/provider"
"istio.io/istio/pkg/cluster"
"istio.io/istio/pkg/config/schema/kind"
"istio.io/istio/pkg/ptr"
"istio.io/istio/pkg/util/sets"
)

Expand Down Expand Up @@ -100,7 +101,8 @@ func (es *EndpointShards) CopyEndpoints(portMap map[string]int) map[int][]*Istio
res := map[int][]*IstioEndpoint{}
for _, v := range es.Shards {
for _, ep := range v {
portNum, f := portMap[ep.ServicePortName]
k := ptr.NonEmptyOrDefault(ep.ServicePortNameKey, ep.ServicePortName)
portNum, f := portMap[k]
if !f {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/model/push_context.go
Expand Up @@ -1446,7 +1446,7 @@ func (ps *PushContext) initServiceRegistry(env *Environment, configsUpdate sets.
for _, s := range allServices {
portMap := map[string]int{}
for _, port := range s.Ports {
portMap[port.Name] = port.Port
portMap[fmt.Sprintf("%s~%d", port.Name, port.Port)] = port.Port
}

svcKey := s.Key()
Expand Down
3 changes: 2 additions & 1 deletion pilot/pkg/model/service.go
Expand Up @@ -485,7 +485,8 @@ type IstioEndpoint struct {
Address string

// ServicePortName tracks the name of the port, this is used to select the IstioEndpoint by service port.
ServicePortName string
ServicePortName string
ServicePortNameKey string

// ServiceAccount holds the associated service account.
ServiceAccount string
Expand Down
12 changes: 7 additions & 5 deletions pilot/pkg/serviceregistry/serviceentry/conversion.go
Expand Up @@ -15,6 +15,7 @@
package serviceentry

import (
"fmt"
"net/netip"
"strings"
"time"
Expand Down Expand Up @@ -341,11 +342,12 @@ func (s *Controller) convertServiceEntryToInstances(cfg config.Config, services
}
out = append(out, &model.ServiceInstance{
Endpoint: &model.IstioEndpoint{
Address: string(service.Hostname),
EndpointPort: endpointPort,
ServicePortName: serviceEntryPort.Name,
Labels: nil,
TLSMode: model.DisabledTLSModeLabel,
Address: string(service.Hostname),
EndpointPort: endpointPort,
ServicePortName: serviceEntryPort.Name,
ServicePortNameKey: fmt.Sprintf("%s~%d", serviceEntryPort.Name, serviceEntryPort.Number),
Labels: nil,
TLSMode: model.DisabledTLSModeLabel,
},
Service: service,
ServicePort: convertPort(serviceEntryPort),
Expand Down

0 comments on commit d17ed67

Please sign in to comment.