diff --git a/agent/agent.go b/agent/agent.go index 192a120ed5b..06f538bf969 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -71,7 +71,6 @@ import ( "github.com/hashicorp/consul/lib/file" "github.com/hashicorp/consul/lib/mutex" "github.com/hashicorp/consul/lib/routine" - "github.com/hashicorp/consul/lib/stringslice" "github.com/hashicorp/consul/logging" "github.com/hashicorp/consul/proto-public/pbresource" "github.com/hashicorp/consul/proto/private/pboperator" @@ -622,7 +621,7 @@ func (a *Agent) Start(ctx context.Context) error { // create the state synchronization manager which performs // regular and on-demand state synchronizations (anti-entropy). a.sync = ae.NewStateSyncer(a.State, c.AEInterval, a.shutdownCh, a.logger) - if a.useV2Resources() { + if a.baseDeps.UseV2Resources() { a.sync.HardDisableSync() } @@ -726,7 +725,7 @@ func (a *Agent) Start(ctx context.Context) error { ) var pt *proxytracker.ProxyTracker - if a.useV2Resources() { + if a.baseDeps.UseV2Resources() { pt = proxyWatcher.(*proxytracker.ProxyTracker) } server, err := consul.NewServer(consulCfg, a.baseDeps.Deps, a.externalGRPCServer, incomingRPCLimiter, serverLogger, pt) @@ -913,20 +912,11 @@ func (a *Agent) Failed() <-chan struct{} { return a.apiServers.failed } -// useV2Resources returns true if "resource-apis" is present in the Experiments -// array of the agent config. -func (a *Agent) useV2Resources() bool { - if stringslice.Contains(a.baseDeps.Experiments, consul.CatalogResourceExperimentName) { - return true - } - return false -} - // getProxyWatcher returns the proper implementation of the ProxyWatcher interface. // It will return a ProxyTracker if "resource-apis" experiment is active. Otherwise, // it will return a ConfigSource. func (a *Agent) getProxyWatcher() xds.ProxyWatcher { - if a.useV2Resources() { + if a.baseDeps.UseV2Resources() { a.logger.Trace("returning proxyTracker for getProxyWatcher") return proxytracker.NewProxyTracker(proxytracker.ProxyTrackerConfig{ Logger: a.logger.Named("proxy-tracker"), diff --git a/agent/consul/options.go b/agent/consul/options.go index 8c9fe05f487..6dc754b3aef 100644 --- a/agent/consul/options.go +++ b/agent/consul/options.go @@ -4,6 +4,7 @@ package consul import ( + "github.com/hashicorp/consul/lib/stringslice" "google.golang.org/grpc" "github.com/hashicorp/consul-net-rpc/net/rpc" @@ -48,6 +49,15 @@ type Deps struct { EnterpriseDeps } +// useV2Resources returns true if "resource-apis" is present in the Experiments +// array of the agent config. +func (d Deps) UseV2Resources() bool { + if stringslice.Contains(d.Experiments, CatalogResourceExperimentName) { + return true + } + return false +} + type GRPCClientConner interface { ClientConn(datacenter string) (*grpc.ClientConn, error) ClientConnLeader() (*grpc.ClientConn, error) diff --git a/agent/consul/server.go b/agent/consul/server.go index f0dd0e8c09b..9540cbe1c0f 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -555,6 +555,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incomingRPCLimiter: incomingRPCLimiter, routineManager: routine.NewManager(logger.Named(logging.ConsulServer)), registry: flat.Registry, + useV2Resources: flat.UseV2Resources(), } incomingRPCLimiter.Register(s) @@ -929,9 +930,7 @@ func isV1CatalogRequest(rpcName string) bool { } func (s *Server) registerControllers(deps Deps, proxyUpdater ProxyUpdater) error { - if stringslice.Contains(deps.Experiments, CatalogResourceExperimentName) { - s.useV2Resources = true - + if s.useV2Resources { catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies()) defaultAllow, err := s.config.ACLResolverSettings.IsDefaultAllow() diff --git a/agent/http.go b/agent/http.go index e6ed0713f66..e95d36c914f 100644 --- a/agent/http.go +++ b/agent/http.go @@ -395,7 +395,7 @@ func (s *HTTPHandlers) wrap(handler endpoint, methods []string) http.HandlerFunc logURL = aclEndpointRE.ReplaceAllString(logURL, "$1$4") rejectCatalogV1Endpoint := false - if s.agent.useV2Resources() { + if s.agent.baseDeps.UseV2Resources() { rejectCatalogV1Endpoint = isV1CatalogRequest(logURL) } @@ -1147,7 +1147,7 @@ func (s *HTTPHandlers) parseToken(req *http.Request, token *string) { } func (s *HTTPHandlers) rejectV1RequestWhenV2Enabled() error { - if s.agent.useV2Resources() { + if s.agent.baseDeps.UseV2Resources() { return newRejectV1RequestWhenV2EnabledError() } return nil diff --git a/agent/testagent.go b/agent/testagent.go index a025f5077ec..037bdc76da6 100644 --- a/agent/testagent.go +++ b/agent/testagent.go @@ -286,7 +286,7 @@ func (a *TestAgent) waitForUp() error { continue // fail, try again } if a.Config.Bootstrap && a.Config.ServerMode { - if a.useV2Resources() { + if a.baseDeps.UseV2Resources() { args := structs.DCSpecificRequest{ Datacenter: "dc1", }