Skip to content

Commit

Permalink
fixing issues with conditional logic and consul-k8s tests not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Jul 2, 2024
1 parent 78363dc commit f988e1e
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions pkg/consuldp/consul_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ func validateConfig(cfg *Config) error {
return errors.New("proxy details not specified")
case cfg.Proxy.ProxyID == "":
return errors.New("proxy ID not specified")
case cfg.Envoy == nil:
case cfg.Mode == ModeTypeSidecar && cfg.Envoy == nil:
return errors.New("envoy settings not specified")
case cfg.Envoy.AdminBindAddress == "":
case cfg.Mode == ModeTypeSidecar && cfg.Envoy.AdminBindAddress == "":
return errors.New("envoy admin bind address not specified")
case cfg.Envoy.AdminBindPort == 0:
case cfg.Mode == ModeTypeSidecar && cfg.Envoy.AdminBindPort == 0:
return errors.New("envoy admin bind port not specified")
case cfg.Logging == nil:
return errors.New("logging settings not specified")
case cfg.XDSServer.BindAddress == "":
case cfg.Mode == ModeTypeSidecar && cfg.XDSServer.BindAddress == "":
return errors.New("envoy xDS bind address not specified")
case !strings.HasPrefix(cfg.XDSServer.BindAddress, "unix://") && !net.ParseIP(cfg.XDSServer.BindAddress).IsLoopback():
case cfg.Mode == ModeTypeSidecar && !strings.HasPrefix(cfg.XDSServer.BindAddress, "unix://") && !net.ParseIP(cfg.XDSServer.BindAddress).IsLoopback():
return errors.New("non-local xDS bind address not allowed")
case cfg.DNSServer.Port != -1 && !net.ParseIP(cfg.DNSServer.BindAddr).IsLoopback():
case cfg.Mode == ModeTypeSidecar && cfg.DNSServer.Port != -1 && !net.ParseIP(cfg.DNSServer.BindAddr).IsLoopback():
return errors.New("non-local DNS proxy bind address not allowed when running as sidecar")
}

Expand Down Expand Up @@ -179,12 +179,13 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
cdp.aclToken = state.Token
cdp.dpServiceClient = pbdataplane.NewDataplaneServiceClient(state.GRPCConn)

err = cdp.setupXDSServer()
if err != nil {
return err
if cdp.cfg.Mode == ModeTypeSidecar {
err = cdp.setupXDSServer()
if err != nil {
return err
}
go cdp.startXDSServer(ctx)
}
go cdp.startXDSServer(ctx)

bootstrapCfg, cfg, err := cdp.bootstrapConfig(ctx)
if err != nil {
cdp.logger.Error("failed to get bootstrap config", "error", err)
Expand All @@ -198,6 +199,20 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
return err
}

doneCh := make(chan error)

// if running as DNS PRoxy, xDS Server and Envoy are disabled, so
// return before configuring them.
if cdp.cfg.Mode == ModeTypeDNSProxy {
go func() {
select {

Check failure on line 208 in pkg/consuldp/consul_dataplane.go

View workflow job for this annotation

GitHub Actions / lint

S1000: should use a simple channel send/receive instead of `select` with a single case (gosimple)
case <-ctx.Done():
doneCh <- nil
}
}()
return <-doneCh
}

proxy, err := envoy.NewProxy(cdp.envoyProxyConfig(cfg))
if err != nil {
cdp.logger.Error("failed to create new proxy", "error", err)
Expand All @@ -220,7 +235,6 @@ func (cdp *ConsulDataplane) Run(ctx context.Context) error {
return err
}

doneCh := make(chan error)
go func() {
select {
case <-ctx.Done():
Expand Down

0 comments on commit f988e1e

Please sign in to comment.