Add generic experiments configuration and use it to enable catalog v2 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
This commit is contained in:
Matt Keeler 2023-06-12 11:32:43 -04:00 committed by GitHub
parent 809c188b34
commit baaf6d84c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 39 additions and 13 deletions

View File

@ -337,7 +337,7 @@ fmt: $(foreach mod,$(GO_MODULES),fmt/$(mod))
.PHONY: fmt/% .PHONY: fmt/%
fmt/%: fmt/%:
@echo "--> Running go fmt ($*)" @echo "--> Running go fmt ($*)"
@cd $* && go fmt ./... @cd $* && gofmt -s -l -w .
.PHONY: lint .PHONY: lint
lint: $(foreach mod,$(GO_MODULES),lint/$(mod)) lint-container-test-deps lint: $(foreach mod,$(GO_MODULES),lint/$(mod)) lint-container-test-deps

View File

@ -828,6 +828,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
Version: stringVal(c.Version), Version: stringVal(c.Version),
VersionPrerelease: stringVal(c.VersionPrerelease), VersionPrerelease: stringVal(c.VersionPrerelease),
VersionMetadata: stringVal(c.VersionMetadata), VersionMetadata: stringVal(c.VersionMetadata),
Experiments: c.Experiments,
// What is a sensible default for BuildDate? // What is a sensible default for BuildDate?
BuildDate: timeValWithDefault(c.BuildDate, time.Date(1970, 1, 00, 00, 00, 01, 0, time.UTC)), BuildDate: timeValWithDefault(c.BuildDate, time.Date(1970, 1, 00, 00, 00, 01, 0, time.UTC)),

View File

@ -183,6 +183,7 @@ type Config struct {
EncryptKey *string `mapstructure:"encrypt" json:"encrypt,omitempty"` EncryptKey *string `mapstructure:"encrypt" json:"encrypt,omitempty"`
EncryptVerifyIncoming *bool `mapstructure:"encrypt_verify_incoming" json:"encrypt_verify_incoming,omitempty"` EncryptVerifyIncoming *bool `mapstructure:"encrypt_verify_incoming" json:"encrypt_verify_incoming,omitempty"`
EncryptVerifyOutgoing *bool `mapstructure:"encrypt_verify_outgoing" json:"encrypt_verify_outgoing,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:"-"` GossipLAN GossipLANConfig `mapstructure:"gossip_lan" json:"-"`
GossipWAN GossipWANConfig `mapstructure:"gossip_wan" json:"-"` GossipWAN GossipWANConfig `mapstructure:"gossip_wan" json:"-"`
HTTPConfig HTTPConfig `mapstructure:"http_config" json:"-"` HTTPConfig HTTPConfig `mapstructure:"http_config" json:"-"`

View File

@ -209,6 +209,9 @@ func DevSource() Source {
ports = { ports = {
grpc = 8502 grpc = 8502
} }
experiments = [
"resource-apis"
]
`, `,
} }
} }

View File

@ -1498,6 +1498,9 @@ type RuntimeConfig struct {
Reporting ReportingConfig Reporting ReportingConfig
// List of experiments to enable
Experiments []string
EnterpriseRuntimeConfig EnterpriseRuntimeConfig
} }

View File

@ -325,6 +325,7 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
rt.DisableAnonymousSignature = true rt.DisableAnonymousSignature = true
rt.DisableKeyringFile = true rt.DisableKeyringFile = true
rt.EnableDebug = true rt.EnableDebug = true
rt.Experiments = []string{"resource-apis"}
rt.UIConfig.Enabled = true rt.UIConfig.Enabled = true
rt.LeaveOnTerm = false rt.LeaveOnTerm = false
rt.Logging.LogLevel = "DEBUG" rt.Logging.LogLevel = "DEBUG"
@ -6355,6 +6356,7 @@ func TestLoad_FullConfig(t *testing.T) {
EnableRemoteScriptChecks: true, EnableRemoteScriptChecks: true,
EnableLocalScriptChecks: true, EnableLocalScriptChecks: true,
EncryptKey: "A4wELWqH", EncryptKey: "A4wELWqH",
Experiments: []string{"foo"},
StaticRuntimeConfig: StaticRuntimeConfig{ StaticRuntimeConfig: StaticRuntimeConfig{
EncryptVerifyIncoming: true, EncryptVerifyIncoming: true,
EncryptVerifyOutgoing: true, EncryptVerifyOutgoing: true,

View File

@ -199,6 +199,7 @@
"EnableRemoteScriptChecks": false, "EnableRemoteScriptChecks": false,
"EncryptKey": "hidden", "EncryptKey": "hidden",
"EnterpriseRuntimeConfig": {}, "EnterpriseRuntimeConfig": {},
"Experiments": [],
"ExposeMaxPort": 0, "ExposeMaxPort": 0,
"ExposeMinPort": 0, "ExposeMinPort": 0,
"GRPCAddrs": [], "GRPCAddrs": [],

View File

@ -285,6 +285,9 @@ enable_syslog = true
encrypt = "A4wELWqH" encrypt = "A4wELWqH"
encrypt_verify_incoming = true encrypt_verify_incoming = true
encrypt_verify_outgoing = true encrypt_verify_outgoing = true
experiments = [
"foo"
]
http_config { http_config {
block_endpoints = [ "RBvAFcGD", "fWOWFznh" ] block_endpoints = [ "RBvAFcGD", "fWOWFznh" ]
allow_write_http_from = [ "127.0.0.1/8", "22.33.44.55/32", "0.0.0.0/0" ] allow_write_http_from = [ "127.0.0.1/8", "22.33.44.55/32", "0.0.0.0/0" ]

View File

@ -327,6 +327,9 @@
"encrypt": "A4wELWqH", "encrypt": "A4wELWqH",
"encrypt_verify_incoming": true, "encrypt_verify_incoming": true,
"encrypt_verify_outgoing": true, "encrypt_verify_outgoing": true,
"experiments": [
"foo"
],
"http_config": { "http_config": {
"block_endpoints": [ "block_endpoints": [
"RBvAFcGD", "RBvAFcGD",
@ -407,11 +410,11 @@
"raft_snapshot_interval": "30s", "raft_snapshot_interval": "30s",
"raft_trailing_logs": 83749, "raft_trailing_logs": 83749,
"raft_logstore": { "raft_logstore": {
"backend" : "wal", "backend": "wal",
"disable_log_cache": true, "disable_log_cache": true,
"verification": { "verification": {
"enabled": true, "enabled": true,
"interval":"12345s" "interval": "12345s"
}, },
"boltdb": { "boltdb": {
"no_freelist_sync": true "no_freelist_sync": true

View File

@ -39,6 +39,8 @@ type Deps struct {
// HCP contains the dependencies required when integrating with the HashiCorp Cloud Platform // HCP contains the dependencies required when integrating with the HashiCorp Cloud Platform
HCP hcp.Deps HCP hcp.Deps
Experiments []string
EnterpriseDeps EnterpriseDeps
} }

View File

@ -79,6 +79,7 @@ import (
raftstorage "github.com/hashicorp/consul/internal/storage/raft" raftstorage "github.com/hashicorp/consul/internal/storage/raft"
"github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/lib/routine" "github.com/hashicorp/consul/lib/routine"
"github.com/hashicorp/consul/lib/stringslice"
"github.com/hashicorp/consul/logging" "github.com/hashicorp/consul/logging"
"github.com/hashicorp/consul/proto-public/pbresource" "github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/proto/private/pbsubscribe" "github.com/hashicorp/consul/proto/private/pbsubscribe"
@ -131,6 +132,8 @@ const (
reconcileChSize = 256 reconcileChSize = 256
LeaderTransferMinVersion = "1.6.0" LeaderTransferMinVersion = "1.6.0"
catalogResourceExperimentName = "resource-apis"
) )
const ( const (
@ -807,7 +810,7 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
s.internalResourceServiceClient, s.internalResourceServiceClient,
logger.Named(logging.ControllerRuntime), logger.Named(logging.ControllerRuntime),
) )
s.registerResources() s.registerResources(flat)
go s.controllerManager.Run(&lib.StopChannelContext{StopCh: shutdownCh}) go s.controllerManager.Run(&lib.StopChannelContext{StopCh: shutdownCh})
go s.trackLeaderChanges() go s.trackLeaderChanges()
@ -858,11 +861,14 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server, incom
return s, nil return s, nil
} }
func (s *Server) registerResources() { func (s *Server) registerResources(deps Deps) {
if stringslice.Contains(deps.Experiments, catalogResourceExperimentName) {
catalog.RegisterTypes(s.typeRegistry) catalog.RegisterTypes(s.typeRegistry)
catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies()) catalog.RegisterControllers(s.controllerManager, catalog.DefaultControllerDependencies())
mesh.RegisterTypes(s.typeRegistry) mesh.RegisterTypes(s.typeRegistry)
}
reaper.RegisterControllers(s.controllerManager) reaper.RegisterControllers(s.controllerManager)
if s.config.DevMode { if s.config.DevMode {

View File

@ -73,6 +73,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
return d, err return d, err
} }
d.WatchedFiles = result.WatchedFiles d.WatchedFiles = result.WatchedFiles
d.Experiments = result.RuntimeConfig.Experiments
cfg := result.RuntimeConfig cfg := result.RuntimeConfig
logConf := cfg.Logging logConf := cfg.Logging
logConf.Name = logging.Agent logConf.Name = logging.Agent