Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down
10 changes: 10 additions & 0 deletions agent/consul/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func (s *HTTPHandlers) wrap(handler endpoint, methods []string) http.HandlerFunc
logURL = aclEndpointRE.ReplaceAllString(logURL, "$1<hidden>$4")

rejectCatalogV1Endpoint := false
if s.agent.useV2Resources() {
if s.agent.baseDeps.UseV2Resources() {
rejectCatalogV1Endpoint = isV1CatalogRequest(logURL)
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion agent/testagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down