Skip to content

Commit

Permalink
Add generic experiments configuration and use it to enable catalog v2…
Browse files Browse the repository at this point in the history
… resources (#17604)

* Add generic experiments configuration and use it to enable catalog v2 resources

* Run formatting with -s as CI will validate that this has been done
  • Loading branch information
mkeeler authored Jun 12, 2023
1 parent 809c188 commit baaf6d8
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ fmt: $(foreach mod,$(GO_MODULES),fmt/$(mod))
.PHONY: fmt/%
fmt/%:
@echo "--> Running go fmt ($*)"
@cd $* && go fmt ./...
@cd $* && gofmt -s -l -w .

.PHONY: lint
lint: $(foreach mod,$(GO_MODULES),lint/$(mod)) lint-container-test-deps
Expand Down
1 change: 1 addition & 0 deletions agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
Version: stringVal(c.Version),
VersionPrerelease: stringVal(c.VersionPrerelease),
VersionMetadata: stringVal(c.VersionMetadata),
Experiments: c.Experiments,
// What is a sensible default for BuildDate?
BuildDate: timeValWithDefault(c.BuildDate, time.Date(1970, 1, 00, 00, 00, 01, 0, time.UTC)),

Expand Down
1 change: 1 addition & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type Config struct {
EncryptKey *string `mapstructure:"encrypt" json:"encrypt,omitempty"`
EncryptVerifyIncoming *bool `mapstructure:"encrypt_verify_incoming" json:"encrypt_verify_incoming,omitempty"`
EncryptVerifyOutgoing *bool `mapstructure:"encrypt_verify_outgoing" json:"encrypt_verify_outgoing,omitempty"`
Experiments []string `mapstructure:"experiments" json:"experiments,omitempty"`
GossipLAN GossipLANConfig `mapstructure:"gossip_lan" json:"-"`
GossipWAN GossipWANConfig `mapstructure:"gossip_wan" json:"-"`
HTTPConfig HTTPConfig `mapstructure:"http_config" json:"-"`
Expand Down
3 changes: 3 additions & 0 deletions agent/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func DevSource() Source {
ports = {
grpc = 8502
}
experiments = [
"resource-apis"
]
`,
}
}
Expand Down
3 changes: 3 additions & 0 deletions agent/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,9 @@ type RuntimeConfig struct {

Reporting ReportingConfig

// List of experiments to enable
Experiments []string

EnterpriseRuntimeConfig
}

Expand Down
2 changes: 2 additions & 0 deletions agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
rt.DisableAnonymousSignature = true
rt.DisableKeyringFile = true
rt.EnableDebug = true
rt.Experiments = []string{"resource-apis"}
rt.UIConfig.Enabled = true
rt.LeaveOnTerm = false
rt.Logging.LogLevel = "DEBUG"
Expand Down Expand Up @@ -6355,6 +6356,7 @@ func TestLoad_FullConfig(t *testing.T) {
EnableRemoteScriptChecks: true,
EnableLocalScriptChecks: true,
EncryptKey: "A4wELWqH",
Experiments: []string{"foo"},
StaticRuntimeConfig: StaticRuntimeConfig{
EncryptVerifyIncoming: true,
EncryptVerifyOutgoing: true,
Expand Down
1 change: 1 addition & 0 deletions agent/config/testdata/TestRuntimeConfig_Sanitize.golden
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"EnableRemoteScriptChecks": false,
"EncryptKey": "hidden",
"EnterpriseRuntimeConfig": {},
"Experiments": [],
"ExposeMaxPort": 0,
"ExposeMinPort": 0,
"GRPCAddrs": [],
Expand Down
3 changes: 3 additions & 0 deletions agent/config/testdata/full-config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ enable_syslog = true
encrypt = "A4wELWqH"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
experiments = [
"foo"
]
http_config {
block_endpoints = [ "RBvAFcGD", "fWOWFznh" ]
allow_write_http_from = [ "127.0.0.1/8", "22.33.44.55/32", "0.0.0.0/0" ]
Expand Down
17 changes: 10 additions & 7 deletions agent/config/testdata/full-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@
"encrypt": "A4wELWqH",
"encrypt_verify_incoming": true,
"encrypt_verify_outgoing": true,
"experiments": [
"foo"
],
"http_config": {
"block_endpoints": [
"RBvAFcGD",
Expand Down Expand Up @@ -407,17 +410,17 @@
"raft_snapshot_interval": "30s",
"raft_trailing_logs": 83749,
"raft_logstore": {
"backend" : "wal",
"disable_log_cache": true,
"backend": "wal",
"disable_log_cache": true,
"verification": {
"enabled": true,
"interval":"12345s"
"enabled": true,
"interval": "12345s"
},
"boltdb": {
"no_freelist_sync": true
"no_freelist_sync": true
},
"wal": {
"segment_size_mb": 15
"segment_size_mb": 15
}
},
"read_replica": true,
Expand Down Expand Up @@ -927,4 +930,4 @@
"xds": {
"update_max_per_second": 9526.2
}
}
}
2 changes: 2 additions & 0 deletions agent/consul/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Deps struct {
// HCP contains the dependencies required when integrating with the HashiCorp Cloud Platform
HCP hcp.Deps

Experiments []string

EnterpriseDeps
}

Expand Down
16 changes: 11 additions & 5 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import (
raftstorage "github.com/hashicorp/consul/internal/storage/raft"
"github.com/hashicorp/consul/lib"
"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/pbsubscribe"
Expand Down Expand Up @@ -131,6 +132,8 @@ const (
reconcileChSize = 256

LeaderTransferMinVersion = "1.6.0"

catalogResourceExperimentName = "resource-apis"
)

const (
Expand Down Expand Up @@ -807,7 +810,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
s.internalResourceServiceClient,
logger.Named(logging.ControllerRuntime),
)
s.registerResources()
s.registerResources(flat)
go s.controllerManager.Run(&lib.StopChannelContext{StopCh: shutdownCh})

go s.trackLeaderChanges()
Expand Down Expand Up @@ -858,11 +861,14 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
return s, nil
}

func (s *Server) registerResources() {
catalog.RegisterTypes(s.typeRegistry)
catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies())
func (s *Server) registerResources(deps Deps) {
if stringslice.Contains(deps.Experiments, catalogResourceExperimentName) {
catalog.RegisterTypes(s.typeRegistry)
catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies())

mesh.RegisterTypes(s.typeRegistry)
}

mesh.RegisterTypes(s.typeRegistry)
reaper.RegisterControllers(s.controllerManager)

if s.config.DevMode {
Expand Down
1 change: 1 addition & 0 deletions agent/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
return d, err
}
d.WatchedFiles = result.WatchedFiles
d.Experiments = result.RuntimeConfig.Experiments
cfg := result.RuntimeConfig
logConf := cfg.Logging
logConf.Name = logging.Agent
Expand Down

0 comments on commit baaf6d8

Please sign in to comment.