diff --git a/agent/agent.go b/agent/agent.go index 1870e477c..ebc5e87b6 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -363,22 +363,24 @@ func (a *Agent) Start() error { // create the proxy process manager and start it. This is purposely // done here after the local state above is loaded in so we can have // a more accurate initial state view. - a.proxyManager = proxy.NewManager() - a.proxyManager.AllowRoot = a.config.ConnectProxyAllowManagedRoot - a.proxyManager.State = a.State - a.proxyManager.Logger = a.logger - if a.config.DataDir != "" { - // DataDir is required for all non-dev mode agents, but we want - // to allow setting the data dir for demos and so on for the agent, - // so do the check above instead. - a.proxyManager.DataDir = filepath.Join(a.config.DataDir, "proxy") + if !c.ConnectTestDisableManagedProxies { + a.proxyManager = proxy.NewManager() + a.proxyManager.AllowRoot = a.config.ConnectProxyAllowManagedRoot + a.proxyManager.State = a.State + a.proxyManager.Logger = a.logger + if a.config.DataDir != "" { + // DataDir is required for all non-dev mode agents, but we want + // to allow setting the data dir for demos and so on for the agent, + // so do the check above instead. + a.proxyManager.DataDir = filepath.Join(a.config.DataDir, "proxy") - // Restore from our snapshot (if it exists) - if err := a.proxyManager.Restore(a.proxyManager.SnapshotPath()); err != nil { - a.logger.Printf("[WARN] agent: error restoring proxy state: %s", err) + // Restore from our snapshot (if it exists) + if err := a.proxyManager.Restore(a.proxyManager.SnapshotPath()); err != nil { + a.logger.Printf("[WARN] agent: error restoring proxy state: %s", err) + } } + go a.proxyManager.Run() } - go a.proxyManager.Run() // Start watching for critical services to deregister, based on their // checks. diff --git a/agent/config/runtime.go b/agent/config/runtime.go index 63a5c5db8..695bff954 100644 --- a/agent/config/runtime.go +++ b/agent/config/runtime.go @@ -661,6 +661,16 @@ type RuntimeConfig struct { // ConnectCAConfig is the config to use for the CA provider. ConnectCAConfig map[string]interface{} + // ConnectTestDisableManagedProxies is not exposed to public config but us + // used by TestAgent to prevent self-executing the test binary in the + // background if a managed proxy is created for a test. The only place we + // actually want to test processes really being spun up and managed is in + // `agent/proxy` and it does it at a lower level. Note that this still allows + // registering managed proxies via API and other methods, and still creates + // all the agent state for them, just doesn't actually start external + // processes up. + ConnectTestDisableManagedProxies bool + // DNSAddrs contains the list of TCP and UDP addresses the DNS server will // bind to. If the DNS endpoint is disabled (ports.dns <= 0) the list is // empty. diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 102e0623e..9852347c6 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -4245,6 +4245,7 @@ func TestSanitize(t *testing.T) { "ConnectProxyDefaultDaemonCommand": [], "ConnectProxyDefaultExecMode": "", "ConnectProxyDefaultScriptCommand": [], + "ConnectTestDisableManagedProxies": false, "ConsulCoordinateUpdateBatchSize": 0, "ConsulCoordinateUpdateMaxBatches": 0, "ConsulCoordinateUpdatePeriod": "15s", diff --git a/agent/testagent.go b/agent/testagent.go index 3703ded1b..4bcd4d40c 100644 --- a/agent/testagent.go +++ b/agent/testagent.go @@ -352,16 +352,6 @@ func TestConfig(sources ...config.Source) *config.RuntimeConfig { ca_config { cluster_id = "` + connect.TestClusterID + `" } - proxy_defaults { - // Generally we don't actually need to test real proxy startup except - // in the Daemon package which explicitly manages how it starts things - // so making this a no-op long running command like /bin/sleep would - // be fine, but there is no such thing on windows etc. We hackily rely - // on the fact that if the executable doesn't exist, the Daemon - // manager will get an exec error and retry it with a backoff beningly - // until tests pass. - daemon_command = ["/bin/sleep", "3600"] - } } performance { raft_multiplier = 1 @@ -386,6 +376,10 @@ func TestConfig(sources ...config.Source) *config.RuntimeConfig { fmt.Println("WARNING:", w) } + // Disable connect proxy execution since it causes all kinds of problems with + // self-executing tests etc. + cfg.ConnectTestDisableManagedProxies = true + return &cfg }