@@ -4,10 +4,11 @@ import (
44 "bytes"
55 "context"
66 "flag"
7- "net "
7+ "fmt "
88 "os"
99 "os/exec"
1010 "path/filepath"
11+ "strings"
1112 "testing"
1213
1314 "github.com/stretchr/testify/mock"
2425
2526func TestBootstrapConfig (t * testing.T ) {
2627 const (
27- serverAddr = "1.2.3.4"
28- nodeName = "agentless-node"
28+ nodeName = "agentless-node"
29+ xdsBindPort = 1234
30+ socketPath = "/var/run/xds.sock"
2931 )
3032
3133 makeStruct := func (kv map [string ]any ) * structpb.Struct {
@@ -42,11 +44,6 @@ func TestBootstrapConfig(t *testing.T) {
4244 & Config {
4345 Consul : & ConsulConfig {
4446 GRPCPort : 1234 ,
45- Credentials : & CredentialsConfig {
46- Static : & StaticCredentialsConfig {
47- Token : "some-acl-token" ,
48- },
49- },
5047 },
5148 Service : & ServiceConfig {
5249 ServiceID : "web-proxy" ,
@@ -59,6 +56,7 @@ func TestBootstrapConfig(t *testing.T) {
5956 Telemetry : & TelemetryConfig {
6057 UseCentralConfig : false ,
6158 },
59+ XDSServer : & XDSServer {BindAddress : "1.2.3.4" , BindPort : xdsBindPort },
6260 },
6361 & pbdataplane.GetEnvoyBootstrapParamsResponse {
6462 Service : "web" ,
@@ -72,11 +70,6 @@ func TestBootstrapConfig(t *testing.T) {
7270 & Config {
7371 Consul : & ConsulConfig {
7472 GRPCPort : 1234 ,
75- Credentials : & CredentialsConfig {
76- Static : & StaticCredentialsConfig {
77- Token : "some-acl-token" ,
78- },
79- },
8073 },
8174 Service : & ServiceConfig {
8275 ServiceID : "web-proxy" ,
@@ -89,6 +82,7 @@ func TestBootstrapConfig(t *testing.T) {
8982 Telemetry : & TelemetryConfig {
9083 UseCentralConfig : true ,
9184 },
85+ XDSServer : & XDSServer {BindAddress : "1.2.3.4" , BindPort : xdsBindPort },
9286 },
9387 & pbdataplane.GetEnvoyBootstrapParamsResponse {
9488 Service : "web" ,
@@ -102,11 +96,6 @@ func TestBootstrapConfig(t *testing.T) {
10296 & Config {
10397 Consul : & ConsulConfig {
10498 GRPCPort : 1234 ,
105- Credentials : & CredentialsConfig {
106- Static : & StaticCredentialsConfig {
107- Token : "some-acl-token" ,
108- },
109- },
11099 },
111100 Service : & ServiceConfig {
112101 ServiceID : "web-proxy" ,
@@ -121,12 +110,65 @@ func TestBootstrapConfig(t *testing.T) {
121110 Telemetry : & TelemetryConfig {
122111 UseCentralConfig : false ,
123112 },
113+ XDSServer : & XDSServer {BindAddress : "1.2.3.4" , BindPort : xdsBindPort },
124114 },
125115 & pbdataplane.GetEnvoyBootstrapParamsResponse {
126116 Service : "web" ,
127117 NodeName : nodeName ,
128118 },
129119 },
120+ "local-xds-server" : {
121+ & Config {
122+ Consul : & ConsulConfig {
123+ GRPCPort : 1234 ,
124+ },
125+ Service : & ServiceConfig {
126+ ServiceID : "web-proxy" ,
127+ NodeName : nodeName ,
128+ },
129+ Envoy : & EnvoyConfig {
130+ AdminBindAddress : "127.0.0.1" ,
131+ AdminBindPort : 19000 ,
132+ },
133+ Telemetry : & TelemetryConfig {
134+ UseCentralConfig : false ,
135+ },
136+ XDSServer : & XDSServer {BindAddress : "127.0.0.1" , BindPort : xdsBindPort },
137+ },
138+ & pbdataplane.GetEnvoyBootstrapParamsResponse {
139+ Service : "web" ,
140+ NodeName : nodeName ,
141+ Config : makeStruct (map [string ]any {
142+ "envoy_dogstatsd_url" : "this-should-not-appear-in-generated-config" ,
143+ }),
144+ },
145+ },
146+ "local-unix-socket-xds-server" : {
147+ & Config {
148+ Consul : & ConsulConfig {
149+ GRPCPort : 1234 ,
150+ },
151+ Service : & ServiceConfig {
152+ ServiceID : "web-proxy" ,
153+ NodeName : nodeName ,
154+ },
155+ Envoy : & EnvoyConfig {
156+ AdminBindAddress : "127.0.0.1" ,
157+ AdminBindPort : 19000 ,
158+ },
159+ Telemetry : & TelemetryConfig {
160+ UseCentralConfig : false ,
161+ },
162+ XDSServer : & XDSServer {BindAddress : fmt .Sprintf ("unix://%s" , socketPath )},
163+ },
164+ & pbdataplane.GetEnvoyBootstrapParamsResponse {
165+ Service : "web" ,
166+ NodeName : nodeName ,
167+ Config : makeStruct (map [string ]any {
168+ "envoy_dogstatsd_url" : "this-should-not-appear-in-generated-config" ,
169+ }),
170+ },
171+ },
130172 }
131173 for desc , tc := range testCases {
132174 t .Run (desc , func (t * testing.T ) {
@@ -144,7 +186,14 @@ func TestBootstrapConfig(t *testing.T) {
144186 dp := & ConsulDataplane {
145187 cfg : tc .cfg ,
146188 dpServiceClient : client ,
147- consulServer : & consulServer {address : net.IPAddr {IP : net .ParseIP (serverAddr )}},
189+ }
190+
191+ if checkLocalXDSServer (tc .cfg .XDSServer .BindAddress ) {
192+ if strings .HasPrefix (tc .cfg .XDSServer .BindAddress , "unix://" ) {
193+ dp .localXDSServer = & localXDSServer {enabled : true , listenerAddress : socketPath , listenerNetwork : "unix" }
194+ } else {
195+ dp .localXDSServer = & localXDSServer {enabled : true , listenerAddress : fmt .Sprintf ("127.0.0.1:%d" , xdsBindPort )}
196+ }
148197 }
149198
150199 bsCfg , err := dp .bootstrapConfig (ctx )
0 commit comments