@@ -30,8 +30,7 @@ type consulServer struct {
3030 grpcClientConn * grpc.ClientConn
3131}
3232
33- type localXDSServer struct {
34- enabled bool
33+ type xdsServer struct {
3534 listener net.Listener
3635 listenerAddress string
3736 listenerNetwork string
@@ -45,7 +44,7 @@ type ConsulDataplane struct {
4544 cfg * Config
4645 consulServer * consulServer
4746 dpServiceClient pbdataplane.DataplaneServiceClient
48- localXDSServer * localXDSServer
47+ xdsServer * xdsServer
4948}
5049
5150// NewConsulDP creates a new instance of ConsulDataplane
@@ -65,9 +64,8 @@ func NewConsulDP(cfg *Config) (*ConsulDataplane, error) {
6564 })
6665
6766 return & ConsulDataplane {
68- logger : logger ,
69- cfg : cfg ,
70- localXDSServer : & localXDSServer {enabled : false },
67+ logger : logger ,
68+ cfg : cfg ,
7169 }, nil
7270}
7371
@@ -93,8 +91,8 @@ func validateConfig(cfg *Config) error {
9391 return errors .New ("logging settings not specified" )
9492 case cfg .XDSServer .BindAddress == "" :
9593 return errors .New ("envoy xDS bind address not specified" )
96- case cfg .XDSServer .BindPort == 0 && ! checkLocalXDSServer ( cfg .XDSServer .BindAddress ) :
97- return errors .New ("envoy xDS bind port not specified " )
94+ case ! strings . HasPrefix ( cfg .XDSServer .BindAddress , "unix://" ) && cfg . XDSServer . BindAddress != "127.0.0.1" && cfg .XDSServer .BindAddress != "localhost" :
95+ return errors .New ("non-local xDS bind address not allowed " )
9896 }
9997 return nil
10098}
@@ -133,28 +131,6 @@ func (cdp *ConsulDataplane) setConsulServerSupportedFeatures(ctx context.Context
133131 return nil
134132}
135133
136- // checkLocalXDSServer checks if the specified xds bind address is local.
137- func checkLocalXDSServer (xdsBindAddr string ) bool {
138- if strings .HasPrefix (xdsBindAddr , "unix://" ) || xdsBindAddr == "127.0.0.1" || xdsBindAddr == "localhost" {
139- return true
140- }
141- return false
142- }
143-
144- // checkAndEnableLocalXDSServer checks if the specified xds bind address is local.
145- // If local, it enables the flag to configure consul-dataplane (later on in the setup process)
146- // with a gRPC server to serve envoy xDS requests.
147- // If not local, the flag remains turned off and it is assumed the xDS requests will be served
148- // by a remote gRPC server.
149- // Potential TODO: Explicitly allow specifying an option (xds.disable?) to disable configuring
150- // consul-dataplane as the xDS server in case xDS requests can be served on another port locally
151- // (example: consul server process on localhost).
152- func (cdp * ConsulDataplane ) checkAndEnableLocalXDSServer () {
153- if checkLocalXDSServer (cdp .cfg .XDSServer .BindAddress ) {
154- cdp .localXDSServer .enabled = true
155- }
156- }
157-
158134func (cdp * ConsulDataplane ) Run (ctx context.Context ) error {
159135 cdp .logger .Info ("started consul-dataplane process" )
160136
@@ -187,16 +163,12 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
187163 return fmt .Errorf ("failed to set supported features: %w" , err )
188164 }
189165
190- cdp .checkAndEnableLocalXDSServer ()
191-
192- if cdp .localXDSServer .enabled {
193- err = cdp .setupXDSServer ()
194- if err != nil {
195- return err
196- }
197- go cdp .startXDSServer ()
198- defer cdp .stopXDSServer ()
166+ err = cdp .setupXDSServer ()
167+ if err != nil {
168+ return err
199169 }
170+ go cdp .startXDSServer ()
171+ defer cdp .stopXDSServer ()
200172
201173 cfg , err := cdp .bootstrapConfig (ctx )
202174 if err != nil {
0 commit comments