Skip to content

Commit

Permalink
remove use of datacenter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Oct 12, 2023
1 parent 1671095 commit e782594
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,9 @@ func (b *Builder) buildDestination(

cpr := destination.ComputedPortRoutes

defaultDC := func(dc string) string {
if destination.Explicit != nil {
dc = orDefault(dc, destination.Explicit.Datacenter)
}
dc = orDefault(dc, b.localDatacenter)
if dc != b.localDatacenter {
panic("cross datacenter service discovery clusters are not supported in v2")
}
return dc
}

var lb *ListenerBuilder
if destination.Explicit != nil {
lb = b.addExplicitOutboundListener(destination.Explicit, defaultDC(""))
lb = b.addExplicitOutboundListener(destination.Explicit)
} else {
lb = tproxyOutboundListenerBuilder
}
Expand All @@ -82,6 +71,17 @@ func (b *Builder) buildDestination(
}
}
}

defaultDC := func(dc string) string {
if destination.Explicit != nil {
dc = orDefault(dc, destination.Explicit.Datacenter)
}
dc = orDefault(dc, b.localDatacenter)
if dc != b.localDatacenter {
panic("cross datacenter service discovery clusters are not supported in v2")
}
return dc
}

statPrefix := DestinationStatPrefix(
cpr.ParentRef.Ref,
Expand All @@ -93,7 +93,7 @@ func (b *Builder) buildDestination(
if destination.Explicit != nil {
routeName = lb.listener.Name
} else {
routeName = DestinationResourceID(cpr.ParentRef.Ref, defaultDC(""))
routeName = DestinationResourceID(cpr.ParentRef.Ref)
}

var (
Expand Down Expand Up @@ -455,13 +455,13 @@ func (b *ListenerBuilder) addL7Router(statPrefix string, protocol pbcatalog.Prot
}

// addExplicitOutboundListener creates an outbound listener for an explicit destination.
func (b *Builder) addExplicitOutboundListener(explicit *pbmesh.Destination, datacenter string) *ListenerBuilder {
listener := makeExplicitListener(explicit, datacenter, pbproxystate.Direction_DIRECTION_OUTBOUND)
func (b *Builder) addExplicitOutboundListener(explicit *pbmesh.Destination) *ListenerBuilder {
listener := makeExplicitListener(explicit, pbproxystate.Direction_DIRECTION_OUTBOUND)

return b.NewListenerBuilder(listener)
}

func makeExplicitListener(explicit *pbmesh.Destination, datacenter string, direction pbproxystate.Direction) *pbproxystate.Listener {
func makeExplicitListener(explicit *pbmesh.Destination, direction pbproxystate.Direction) *pbproxystate.Listener {
if explicit == nil {
panic("explicit upstream required")
}
Expand All @@ -482,7 +482,7 @@ func makeExplicitListener(explicit *pbmesh.Destination, datacenter string, direc
Port: destinationAddr.IpPort.Port,
},
}
listener.Name = DestinationListenerName(explicit.DestinationRef, datacenter, explicit.DestinationPort, destinationAddr.IpPort.Ip, destinationAddr.IpPort.Port)
listener.Name = DestinationListenerName(explicit.DestinationRef, explicit.DestinationPort, destinationAddr.IpPort.Ip, destinationAddr.IpPort.Port)
case *pbmesh.Destination_Unix:
destinationAddr := explicit.ListenAddr.(*pbmesh.Destination_Unix)
listener.BindAddress = &pbproxystate.Listener_UnixSocket{
Expand All @@ -491,7 +491,7 @@ func makeExplicitListener(explicit *pbmesh.Destination, datacenter string, direc
Mode: destinationAddr.Unix.Mode,
},
}
listener.Name = DestinationListenerName(explicit.DestinationRef, datacenter, explicit.DestinationPort, destinationAddr.Unix.Path, 0)
listener.Name = DestinationListenerName(explicit.DestinationRef, explicit.DestinationPort, destinationAddr.Unix.Path, 0)
}

return listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ func DestinationStatPrefix(serviceRef *pbresource.Reference, portName, datacente
datacenter)
}

func DestinationListenerName(destinationRef *pbresource.Reference, datacenter, portName string, address string, port uint32) string {
func DestinationListenerName(destinationRef *pbresource.Reference, portName string, address string, port uint32) string {
name := fmt.Sprintf("%s:%s:%s", DestinationResourceID(destinationRef), portName, address)
if port != 0 {
return fmt.Sprintf("%s:%s:%s:%d", DestinationResourceID(destinationRef, datacenter), portName, address, port)
return fmt.Sprintf("%s:%d", name, port)
}

return fmt.Sprintf("%s:%s:%s", DestinationResourceID(destinationRef, datacenter), portName, address)
return name
}

// XDSResourceID returns a string representation that uniquely identifies the
// upstream in a canonical but human readable way.
func DestinationResourceID(destinationRef *pbresource.Reference, datacenter string) string {
tenancyPrefix := fmt.Sprintf("%s/%s/%s/%s", destinationRef.Tenancy.Partition,
destinationRef.Tenancy.PeerName, destinationRef.Tenancy.Namespace,
datacenter)
func DestinationResourceID(destinationRef *pbresource.Reference) string {
tenancyPrefix := fmt.Sprintf("%s/%s/%s", destinationRef.Tenancy.Partition,
destinationRef.Tenancy.PeerName, destinationRef.Tenancy.Namespace)
return fmt.Sprintf("%s/%s", tenancyPrefix, destinationRef.Name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"host": "1.1.1.1",
"port": 1234
},
"name": "default/local/default/dc1/api-1:tcp:1.1.1.1:1234",
"name": "default/local/default/api-1:tcp:1.1.1.1:1234",
"routers": [
{
"l4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"host": "1.1.1.1",
"port": 1234
},
"name": "default/local/default/dc1/api-1:tcp:1.1.1.1:1234",
"name": "default/local/default/api-1:tcp:1.1.1.1:1234",
"routers": [
{
"l4": {
Expand All @@ -167,7 +167,7 @@
},
{
"direction": "DIRECTION_OUTBOUND",
"name": "default/local/default/dc1/api-2:tcp:/path/to/socket",
"name": "default/local/default/api-2:tcp:/path/to/socket",
"routers": [
{
"l4": {
Expand All @@ -189,7 +189,7 @@
"host": "1.1.1.1",
"port": 2345
},
"name": "default/local/default/dc1/api-1:tcp2:1.1.1.1:2345",
"name": "default/local/default/api-1:tcp2:1.1.1.1:2345",
"routers": [
{
"l4": {
Expand All @@ -216,7 +216,7 @@
},
{
"direction": "DIRECTION_OUTBOUND",
"name": "default/local/default/dc1/api-2:tcp2:/path/to/socket",
"name": "default/local/default/api-2:tcp2:/path/to/socket",
"routers": [
{
"l4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"host": "1.1.1.1",
"port": 1234
},
"name": "default/local/default/dc1/api-1:tcp:1.1.1.1:1234",
"name": "default/local/default/api-1:tcp:1.1.1.1:1234",
"routers": [
{
"l4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"listeners": [
{
"direction": "DIRECTION_OUTBOUND",
"name": "default/local/default/dc1/api-2:tcp:/path/to/socket",
"name": "default/local/default/api-2:tcp:/path/to/socket",
"routers": [
{
"l4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"host": "1.1.1.1",
"port": 1234
},
"name": "default/local/default/dc1/api-1:tcp:1.1.1.1:1234",
"name": "default/local/default/api-1:tcp:1.1.1.1:1234",
"routers": [
{
"l4": {
Expand All @@ -199,7 +199,7 @@
},
{
"direction": "DIRECTION_OUTBOUND",
"name": "default/local/default/dc1/api-2:tcp:/path/to/socket",
"name": "default/local/default/api-2:tcp:/path/to/socket",
"routers": [
{
"l4": {
Expand All @@ -221,22 +221,22 @@
"host": "1.1.1.1",
"port": 1234
},
"name": "default/local/default/dc1/api-1:http:1.1.1.1:1234",
"name": "default/local/default/api-1:http:1.1.1.1:1234",
"routers": [
{
"l7": {
"name": "default/local/default/dc1/api-1:http:1.1.1.1:1234",
"name": "default/local/default/api-1:http:1.1.1.1:1234",
"statPrefix": "upstream."
}
}
]
}
],
"routes": {
"default/local/default/dc1/api-1:http:1.1.1.1:1234": {
"default/local/default/api-1:http:1.1.1.1:1234": {
"virtualHosts": [
{
"name": "default/local/default/dc1/api-1:http:1.1.1.1:1234",
"name": "default/local/default/api-1:http:1.1.1.1:1234",
"routeRules": [
{
"destination": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@
}
],
"routes": {
"default/local/default/dc1/api-app": {
"default/local/default/api-app": {
"virtualHosts": [
{
"name": "default/local/default/dc1/api-app",
"name": "default/local/default/api-app",
"routeRules": [
{
"destination": {
Expand All @@ -342,10 +342,10 @@
}
]
},
"default/local/default/dc1/api-app2": {
"default/local/default/api-app2": {
"virtualHosts": [
{
"name": "default/local/default/dc1/api-app2",
"name": "default/local/default/api-app2",
"routeRules": [
{
"destination": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@
}
],
"routes": {
"default/local/default/dc1/api-app": {
"default/local/default/api-app": {
"virtualHosts": [
{
"name": "default/local/default/dc1/api-app",
"name": "default/local/default/api-app",
"routeRules": [
{
"destination": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@
}
],
"routes": {
"default/local/default/dc1/api-app": {
"default/local/default/api-app": {
"virtualHosts": [
{
"name": "default/local/default/dc1/api-app",
"name": "default/local/default/api-app",
"routeRules": [
{
"destination": {
Expand Down

0 comments on commit e782594

Please sign in to comment.