mirror of https://github.com/status-im/consul.git
Add server receiver to routes and log tgw err
This commit is contained in:
parent
cd4cf5161f
commit
959d9913b8
|
@ -3,6 +3,7 @@ package xds
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/hashicorp/consul/logging"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
|
@ -18,7 +19,7 @@ import (
|
|||
|
||||
// routesFromSnapshot returns the xDS API representation of the "routes" in the
|
||||
// snapshot.
|
||||
func routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) {
|
||||
func (s *Server) routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) {
|
||||
if cfgSnap == nil {
|
||||
return nil, errors.New("nil config given")
|
||||
}
|
||||
|
@ -29,7 +30,7 @@ func routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot)
|
|||
case structs.ServiceKindIngressGateway:
|
||||
return routesForIngressGateway(cInfo, cfgSnap.IngressGateway.Upstreams, cfgSnap.IngressGateway.DiscoveryChain)
|
||||
case structs.ServiceKindTerminatingGateway:
|
||||
return routesFromSnapshotTerminatingGateway(cInfo, cfgSnap)
|
||||
return s.routesFromSnapshotTerminatingGateway(cInfo, cfgSnap)
|
||||
default:
|
||||
return nil, fmt.Errorf("Invalid service kind: %v", cfgSnap.Kind)
|
||||
}
|
||||
|
@ -37,10 +38,11 @@ func routesFromSnapshot(cInfo connectionInfo, cfgSnap *proxycfg.ConfigSnapshot)
|
|||
|
||||
// routesFromSnapshotTerminatingGateway returns the xDS API representation of the "routes" in the snapshot.
|
||||
// For any HTTP service we will return a default route.
|
||||
func routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) {
|
||||
func (s *Server) routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, error) {
|
||||
if cfgSnap == nil {
|
||||
return nil, errors.New("nil config given")
|
||||
}
|
||||
logger := s.Logger.Named(logging.TerminatingGateway)
|
||||
|
||||
var resources []proto.Message
|
||||
for _, svc := range cfgSnap.TerminatingGateway.ValidServices() {
|
||||
|
@ -69,6 +71,7 @@ func routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.Co
|
|||
}
|
||||
route, err := makeNamedDefaultRouteWithLB(clusterName, lb)
|
||||
if err != nil {
|
||||
logger.Error("failed to make route", "cluster", clusterName, "error", err)
|
||||
continue
|
||||
}
|
||||
resources = append(resources, route)
|
||||
|
@ -78,6 +81,7 @@ func routesFromSnapshotTerminatingGateway(_ connectionInfo, cfgSnap *proxycfg.Co
|
|||
clusterName = connect.ServiceSNI(svc.Name, name, svc.NamespaceOrDefault(), cfgSnap.Datacenter, cfgSnap.Roots.TrustDomain)
|
||||
route, err := makeNamedDefaultRouteWithLB(clusterName, lb)
|
||||
if err != nil {
|
||||
logger.Error("failed to make route", "cluster", clusterName, "error", err)
|
||||
continue
|
||||
}
|
||||
resources = append(resources, route)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/hashicorp/consul/agent/proxycfg"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/agent/xds/proxysupport"
|
||||
"github.com/hashicorp/consul/sdk/testutil"
|
||||
testinf "github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -257,11 +258,15 @@ func TestRoutesFromSnapshot(t *testing.T) {
|
|||
tt.setup(snap)
|
||||
}
|
||||
|
||||
logger := testutil.Logger(t)
|
||||
s := Server{
|
||||
Logger: logger,
|
||||
}
|
||||
cInfo := connectionInfo{
|
||||
Token: "my-token",
|
||||
ProxyFeatures: sf,
|
||||
}
|
||||
routes, err := routesFromSnapshot(cInfo, snap)
|
||||
routes, err := s.routesFromSnapshot(cInfo, snap)
|
||||
require.NoError(err)
|
||||
sort.Slice(routes, func(i, j int) bool {
|
||||
return routes[i].(*envoy.RouteConfiguration).Name < routes[j].(*envoy.RouteConfiguration).Name
|
||||
|
|
|
@ -218,7 +218,7 @@ func (s *Server) process(stream ADSStream, reqCh <-chan *envoy.DiscoveryRequest)
|
|||
},
|
||||
RouteType: {
|
||||
typeURL: RouteType,
|
||||
resources: routesFromSnapshot,
|
||||
resources: s.routesFromSnapshot,
|
||||
stream: stream,
|
||||
allowEmptyFn: func(cfgSnap *proxycfg.ConfigSnapshot) bool {
|
||||
return cfgSnap.Kind == structs.ServiceKindIngressGateway
|
||||
|
|
Loading…
Reference in New Issue