Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jul 8, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10572.txt
@@ -0,0 +1,3 @@
```release-note:feature
config: add agent config flag for enterprise clients to indicate they wish to join a particular partition
```
3 changes: 3 additions & 0 deletions agent/config/builder_oss.go
Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions agent/config/config.go
Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions agent/config/runtime_oss.go
Expand Up @@ -3,3 +3,5 @@
package config

type EnterpriseRuntimeConfig struct{}

func (c *RuntimeConfig) PartitionOrEmpty() string { return "" }
60 changes: 60 additions & 0 deletions agent/config/runtime_oss_test.go
Expand Up @@ -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) {}
Expand All @@ -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))
}
}
}
1 change: 1 addition & 0 deletions agent/config/testdata/full-config.hcl
Expand Up @@ -297,6 +297,7 @@ node_meta {
}
node_name = "otlLxGaI"
non_voting_server = true
partition = ""
performance {
leave_drain_time = "8265s"
raft_multiplier = 5
Expand Down
1 change: 1 addition & 0 deletions agent/config/testdata/full-config.json
Expand Up @@ -297,6 +297,7 @@
},
"node_name": "otlLxGaI",
"non_voting_server": true,
"partition": "",
"performance": {
"leave_drain_time": "8265s",
"raft_multiplier": 5,
Expand Down
3 changes: 3 additions & 0 deletions command/agent/agent.go
Expand Up @@ -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,
Expand Down