config: add agent config flag for enterprise clients to indicate they wish to join a particular partition (#10572)

This commit is contained in:
R.B. Boyer 2021-07-08 10:03:38 -05:00 committed by GitHub
parent 7f083f70ca
commit c94b8c6a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 0 deletions

3
.changelog/10572.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:feature
config: add agent config flag for enterprise clients to indicate they wish to join a particular partition
```

View File

@ -25,6 +25,9 @@ func validateEnterpriseConfigKeys(config *Config) []error {
if len(config.Segments) > 0 {
add("segments")
}
if stringVal(config.Partition) != "" {
add("partition")
}
if stringVal(config.Autopilot.RedundancyZoneTag) != "" {
add("autopilot.redundancy_zone_tag")
}

View File

@ -290,6 +290,8 @@ type Config struct {
SegmentName *string `mapstructure:"segment"`
// Enterprise Only
Segments []Segment `mapstructure:"segments"`
// Enterprise Only
Partition *string `mapstructure:"partition"`
// Enterprise Only - not user configurable
LicensePollBaseTime *string `mapstructure:"license_poll_base_time"`

View File

@ -3,3 +3,5 @@
package config
type EnterpriseRuntimeConfig struct{}
func (c *RuntimeConfig) PartitionOrEmpty() string { return "" }

View File

@ -2,6 +2,14 @@
package config
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/consul/sdk/testutil"
)
var testRuntimeConfigSanitizeExpectedFilename = "TestRuntimeConfig_Sanitize.golden"
func entFullRuntimeConfig(rt *RuntimeConfig) {}
@ -19,3 +27,55 @@ var enterpriseConfigKeyWarnings = []string{
enterpriseConfigKeyError{key: "acl.tokens.managed_service_provider"}.Error(),
enterpriseConfigKeyError{key: "audit"}.Error(),
}
// OSS-only equivalent of TestConfigFlagsAndEdgecases
// used for flags validated in ent-only code
func TestLoad_IntegrationWithFlags_OSS(t *testing.T) {
dataDir := testutil.TempDir(t, "consul")
defer os.RemoveAll(dataDir)
tests := []testCase{
{
desc: "partition config on a client",
args: []string{
`-data-dir=` + dataDir,
`-server=false`,
},
json: []string{`{ "partition": "foo" }`},
hcl: []string{`partition = "foo"`},
expectedWarnings: []string{
`"partition" is a Consul Enterprise configuration and will have no effect`,
},
expected: func(rt *RuntimeConfig) {
rt.DataDir = dataDir
rt.ServerMode = false
},
},
{
desc: "partition config on a server",
args: []string{
`-data-dir=` + dataDir,
`-server`,
},
json: []string{`{ "partition": "foo" }`},
hcl: []string{`partition = "foo"`},
expectedWarnings: []string{
`"partition" is a Consul Enterprise configuration and will have no effect`,
},
expected: func(rt *RuntimeConfig) {
rt.DataDir = dataDir
rt.ServerMode = true
rt.LeaveOnTerm = false
rt.SkipLeaveOnInt = true
rt.RPCConfig.EnableStreaming = true
},
},
}
for _, tc := range tests {
for _, format := range []string{"json", "hcl"} {
name := fmt.Sprintf("%v_%v", tc.desc, format)
t.Run(name, tc.run(format, dataDir))
}
}
}

View File

@ -297,6 +297,7 @@ node_meta {
}
node_name = "otlLxGaI"
non_voting_server = true
partition = ""
performance {
leave_drain_time = "8265s"
raft_multiplier = 5

View File

@ -297,6 +297,7 @@
},
"node_name": "otlLxGaI",
"non_voting_server": true,
"partition": "",
"performance": {
"leave_drain_time": "8265s",
"raft_multiplier": 5,

View File

@ -195,6 +195,9 @@ func (c *cmd) run(args []string) int {
ui.Info(fmt.Sprintf(" Version: '%s'", c.versionHuman))
ui.Info(fmt.Sprintf(" Node ID: '%s'", config.NodeID))
ui.Info(fmt.Sprintf(" Node name: '%s'", config.NodeName))
if ap := config.PartitionOrEmpty(); ap != "" {
ui.Info(fmt.Sprintf(" Partition: '%s'", ap))
}
ui.Info(fmt.Sprintf(" Datacenter: '%s' (Segment: '%s')", config.Datacenter, segment))
ui.Info(fmt.Sprintf(" Server: %v (Bootstrap: %v)", config.ServerMode, config.Bootstrap))
ui.Info(fmt.Sprintf(" Client Addr: %v (HTTP: %d, HTTPS: %d, gRPC: %d, DNS: %d)", config.ClientAddrs,