Skip to content

Commit

Permalink
Fix tests and use "-partition" flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Venkatesh committed Sep 17, 2021
1 parent 41224b4 commit 7bf487f
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ executors:
- image: docker.mirror.hashicorp.services/circleci/golang:1.16
environment:
TEST_RESULTS: /tmp/test-results # path to where test results are saved
CONSUL_VERSION: 1.10.2 # Consul's OSS version to use in tests
CONSUL_ENT_VERSION: 1.10.2+ent # Consul's enterprise version to use in tests
CONSUL_VERSION: 1.11.0-alpha # Consul's OSS version to use in tests
CONSUL_ENT_VERSION: 1.11.0+ent-alpha # Consul's enterprise version to use in tests

control-plane-path : &control-plane-path control-plane
acceptance-test-path: &acceptance-test-path charts/consul/test/acceptance
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/connect-inject-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec:
{{- end }}
{{- if .Values.global.adminPartitions.enabled }}
-enable-partitions=true \
-partition-name={{ .Values.global.adminPartitions.name }} \
-partition={{ .Values.global.adminPartitions.name }} \
{{- end }}
{{- if .Values.global.enableConsulNamespaces }}
-enable-namespaces=true \
Expand Down
12 changes: 0 additions & 12 deletions charts/consul/test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -714,18 +714,6 @@ EOF
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: partition name set with .global.adminPartitions.enabled=true" {
cd `chart_dir`
local actual=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'global.adminPartitions.enabled=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command | any(contains("partition-name=default"))' | tee /dev/stderr)

[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: fails if namespaces are disabled and .global.adminPartitions.enabled=true" {
cd `chart_dir`
run helm template \
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/ingressgateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (in *IngressGateway) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.IngressGatewayConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.IngressGatewayConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *IngressGateway) Validate(namespacesEnabled bool) error {
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/mesh_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (in *Mesh) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.MeshConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.MeshConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *Mesh) Validate(_ bool) error {
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/proxydefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (in *ProxyDefaults) MatchesConsul(candidate api.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ProxyConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(),
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ProxyConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(),
cmp.Comparer(transparentProxyConfigComparer))
}

Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (in *ServiceDefaults) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(),
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(),
cmp.Comparer(transparentProxyConfigComparer))
}

Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/serviceintentions_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (in *ServiceIntentions) MatchesConsul(candidate api.ConfigEntry) bool {
return cmp.Equal(
in.ToConsul(""),
configEntry,
cmpopts.IgnoreFields(capi.ServiceIntentionsConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"),
cmpopts.IgnoreFields(capi.ServiceIntentionsConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"),
cmpopts.IgnoreFields(capi.SourceIntention{}, "LegacyID", "LegacyMeta", "LegacyCreateTime", "LegacyUpdateTime", "Precedence", "Type"),
cmpopts.IgnoreUnexported(),
cmpopts.EquateEmpty(),
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/serviceresolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (in *ServiceResolver) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceResolverConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceResolverConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *ServiceResolver) ConsulGlobalResource() bool {
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/servicerouter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (in *ServiceRouter) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceRouterConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceRouterConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *ServiceRouter) Validate(namespacesEnabled bool) error {
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/servicesplitter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (in *ServiceSplitter) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceSplitterConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceSplitterConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *ServiceSplitter) Validate(namespacesEnabled bool) error {
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/v1alpha1/terminatinggateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (in *TerminatingGateway) MatchesConsul(candidate capi.ConfigEntry) bool {
return false
}
// No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality.
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.TerminatingGatewayConfigEntry{}, "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.TerminatingGatewayConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *TerminatingGateway) Validate(namespacesEnabled bool) error {
Expand Down
4 changes: 2 additions & 2 deletions control-plane/connect-inject/endpoints_controller_ent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func TestReconcileCreateEndpointWithNamespaces(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, 1, len(check))
// Ignoring Namespace because the response from ENT includes it and OSS does not.
var ignoredFields = []string{"Node", "Definition", "Namespace"}
var ignoredFields = []string{"Node", "Definition", "Namespace", "Partition"}
require.True(t, cmp.Equal(check[setup.expectedAgentHealthChecks[i].CheckID], setup.expectedAgentHealthChecks[i], cmpopts.IgnoreFields(api.AgentCheck{}, ignoredFields...)))
}
}
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func TestReconcileUpdateEndpointWithNamespaces(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, 1, len(check))
// Ignoring Namespace because the response from ENT includes it and OSS does not.
var ignoredFields = []string{"Node", "Definition", "Namespace"}
var ignoredFields = []string{"Node", "Definition", "Namespace", "Partition"}
require.True(t, cmp.Equal(check[tt.expectedAgentHealthChecks[i].CheckID], tt.expectedAgentHealthChecks[i], cmpopts.IgnoreFields(api.AgentCheck{}, ignoredFields...)))
}
}
Expand Down
25 changes: 3 additions & 22 deletions control-plane/connect-inject/endpoints_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,25 +351,6 @@ func TestProcessUpstreams(t *testing.T) {
consulNamespacesEnabled: true,
consulPartitionsEnabled: true,
},
{
name: "single upstream with partition",
pod: func() *corev1.Pod {
pod1 := createPod("pod1", "1.2.3.4", true, true)
pod1.Annotations[annotationUpstreams] = "upstream.default.bar:1234"
return pod1
},
expected: []api.Upstream{
{
DestinationType: api.UpstreamDestTypeService,
DestinationName: "upstream",
LocalBindPort: 1234,
DestinationNamespace: "default",
DestinationPartition: "bar",
},
},
consulNamespacesEnabled: false,
consulPartitionsEnabled: true,
},
{
name: "multiple upstreams",
pod: func() *corev1.Pod {
Expand Down Expand Up @@ -1096,7 +1077,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
// of the regular require.Equal call since it supports ignoring certain
// fields.
diff := cmp.Diff(tt.expectedProxySvcInstances[i].ServiceProxy, instance.ServiceProxy,
cmpopts.IgnoreFields(api.Upstream{}, "DestinationNamespace"))
cmpopts.IgnoreFields(api.Upstream{}, "DestinationNamespace", "DestinationPartition"))
require.Empty(t, diff, "expected objects to be equal")
}

Expand All @@ -1118,7 +1099,7 @@ func TestReconcileCreateEndpoint(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, len(check), 1)
// Ignoring Namespace because the response from ENT includes it and OSS does not.
var ignoredFields = []string{"Node", "Definition", "Namespace"}
var ignoredFields = []string{"Node", "Definition", "Namespace", "Partition"}
require.True(t, cmp.Equal(check[tt.expectedAgentHealthChecks[i].CheckID], tt.expectedAgentHealthChecks[i], cmpopts.IgnoreFields(api.AgentCheck{}, ignoredFields...)))
}
}
Expand Down Expand Up @@ -2464,7 +2445,7 @@ func TestReconcileUpdateEndpoint(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, len(check), 1)
// Ignoring Namespace because the response from ENT includes it and OSS does not.
var ignoredFields = []string{"Node", "Definition", "Namespace"}
var ignoredFields = []string{"Node", "Definition", "Namespace", "Partition"}
require.True(t, cmp.Equal(check[tt.expectedAgentHealthChecks[i].CheckID], tt.expectedAgentHealthChecks[i], cmpopts.IgnoreFields(api.AgentCheck{}, ignoredFields...)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion control-plane/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/go-cmp v0.5.6
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/consul/api v1.10.1-0.20210913215352-5b658d2f392d
github.com/hashicorp/consul/api v1.10.1-0.20210915232521-e0a7900f52bf
github.com/hashicorp/consul/sdk v0.8.0
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f
Expand Down
2 changes: 2 additions & 0 deletions control-plane/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/api v1.10.1-0.20210913215352-5b658d2f392d h1:IBMYvG34CbxQqM55tBk8aVtmIQxvcczI0BqyxmbQDBs=
github.com/hashicorp/consul/api v1.10.1-0.20210913215352-5b658d2f392d/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk=
github.com/hashicorp/consul/api v1.10.1-0.20210915232521-e0a7900f52bf h1:fouyN8SkrE4py09XaOru4PCM9zunem39CjOrMJMrKsc=
github.com/hashicorp/consul/api v1.10.1-0.20210915232521-e0a7900f52bf/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
github.com/hashicorp/consul/sdk v0.8.0 h1:OJtKBtEjboEZvG6AOUdh4Z1Zbyu0WcxQ0qatRrZHTVU=
Expand Down
3 changes: 0 additions & 3 deletions control-plane/subcommand/connect-init/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Command struct {
UI cli.Ui

flagACLAuthMethod string // Auth Method to use for ACLs, if enabled.
flagPartition string // Admin Partition name. Consul Enterprise 1.11+ feature.
flagPodName string // Pod name.
flagPodNamespace string // Pod namespace.
flagAuthMethodNamespace string // Consul namespace the auth-method is defined in.
Expand All @@ -58,7 +57,6 @@ type Command struct {
func (c *Command) init() {
c.flagSet = flag.NewFlagSet("", flag.ContinueOnError)
c.flagSet.StringVar(&c.flagACLAuthMethod, "acl-auth-method", "", "Name of the auth method to login to.")
c.flagSet.StringVar(&c.flagPartition, "partition", "", "Name of the Admin Partition of deployment.")
c.flagSet.StringVar(&c.flagPodName, "pod-name", "", "Name of the pod.")
c.flagSet.StringVar(&c.flagPodNamespace, "pod-namespace", "", "Name of the pod namespace.")
c.flagSet.StringVar(&c.flagAuthMethodNamespace, "auth-method-namespace", "", "Consul namespace the auth-method is defined in")
Expand Down Expand Up @@ -120,7 +118,6 @@ func (c *Command) Run(args []string) int {
}
}
cfg := api.DefaultConfig()
cfg.Partition = c.flagPartition
cfg.Namespace = c.flagConsulServiceNamespace
c.http.MergeOntoConfig(cfg)
consulClient, err := consul.NewClient(cfg)
Expand Down
1 change: 0 additions & 1 deletion control-plane/subcommand/connect-init/command_ent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ func TestRun_ServicePollingWithACLsAndTLSWithNamespaces(t *testing.T) {
tokenSinkFile: tokenFile,
proxyIDFile: proxyFile,
serviceRegistrationPollingAttempts: 5,
flagPartition: c.adminPartition,
}
// We build the http-addr because normally it's defined by the init container setting
// CONSUL_HTTP_ADDR when it processes the command template.
Expand Down
3 changes: 0 additions & 3 deletions control-plane/subcommand/controller/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Command struct {
flagEnableLeaderElection bool
flagEnableWebhooks bool
flagDatacenter string
flagPartition string
flagLogLevel string
flagLogJSON bool

Expand Down Expand Up @@ -65,8 +64,6 @@ func (c *Command) init() {
"Enabling this will ensure there is only one active controller manager.")
c.flagSet.StringVar(&c.flagDatacenter, "datacenter", "",
"Name of the Consul datacenter the controller is operating in. This is added as metadata on managed custom resources.")
c.flagSet.StringVar(&c.flagPartition, "partition", "",
"Name of the Consul Admin Partition the controller is operating in. The config entries are created in this partition.")
c.flagSet.BoolVar(&c.flagEnableNamespaces, "enable-namespaces", false,
"[Enterprise Only] Enables Consul Enterprise namespaces, in either a single Consul namespace or mirrored.")
c.flagSet.StringVar(&c.flagConsulDestinationNamespace, "consul-destination-namespace", "default",
Expand Down
6 changes: 5 additions & 1 deletion control-plane/subcommand/flags/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (f *HTTPFlags) Flags() *flag.FlagSet {
"The server name to use as the SNI host when connecting via TLS. This "+
"can also be specified via the CONSUL_TLS_SERVER_NAME environment variable.")
fs.Var(&f.partition, "partition",
"[Enterprise Only] Name of the Consul Admin Partition the controller is operating in. The config entries are created in this partition.")
"[Enterprise Only] Name of the Consul Admin Partition to query. Default to \"default\" if Admin Partitions are enabled.")
return fs
}

Expand Down Expand Up @@ -96,6 +96,10 @@ func (f *HTTPFlags) ReadTokenFile() (string, error) {
return strings.TrimSpace(string(data)), nil
}

func (f *HTTPFlags) Partition() string {
return f.partition.String()
}

func (f *HTTPFlags) APIClient() (*api.Client, error) {
c := api.DefaultConfig()

Expand Down
4 changes: 4 additions & 0 deletions control-plane/subcommand/flags/usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ HTTP API Options
can also be set to HTTPS by setting the environment variable
CONSUL_HTTP_SSL=true.
-partition=<value>
[Enterprise Only] Name of the Consul Admin Partition to query.
Default to "default" if Admin Partitions are enabled.
-tls-server-name=<value>
The server name to use as the SNI host when connecting via
TLS. This can also be specified via the CONSUL_TLS_SERVER_NAME
Expand Down
15 changes: 6 additions & 9 deletions control-plane/subcommand/inject-connect/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ type Command struct {
flagAllowK8sNamespacesList []string // K8s namespaces to explicitly inject
flagDenyK8sNamespacesList []string // K8s namespaces to deny injection (has precedence)

flagEnablePartitions bool // Use Admin Partitions on all components
flagPartitionName string // Name of Admin Partition if enabled.
flagEnablePartitions bool // Use Admin Partitions on all components

// Flags to support Consul namespaces
flagEnableNamespaces bool // Use namespacing on all components
Expand Down Expand Up @@ -146,8 +145,6 @@ func (c *Command) init() {
c.flagSet.StringVar(&c.flagReleaseNamespace, "release-namespace", "default", "The Consul Helm installation namespace, e.g 'helm install <RELEASE-NAME> --namespace <RELEASE-NAMESPACE>'")
c.flagSet.BoolVar(&c.flagEnablePartitions, "enable-partitions", false,
"[Enterprise Only] Enables Admin Partitions.")
c.flagSet.StringVar(&c.flagPartitionName, "partition-name", "",
"[Enterprise Only] Name of the Admin Partition.")
c.flagSet.BoolVar(&c.flagEnableNamespaces, "enable-namespaces", false,
"[Enterprise Only] Enables namespaces, in either a single Consul namespace or mirrored.")
c.flagSet.StringVar(&c.flagConsulDestinationNamespace, "consul-destination-namespace", "default",
Expand Down Expand Up @@ -235,12 +232,14 @@ func (c *Command) Run(args []string) int {
return 1
}

if c.flagEnablePartitions && c.flagPartitionName == "" {
if c.flagEnablePartitions && c.http.Partition() == "" {
c.UI.Error("-partition-name must set if -enable-partitions is set to 'true'")
return 1
}

if c.flagPartitionName != "" && !c.flagEnablePartitions {
if c.http.Partition() != "" && !c.flagEnablePartitions {
c.UI.Error("-enable-partitions must be set to 'true' if -partition-name is set")
return 1
}

// Proxy resources.
Expand Down Expand Up @@ -349,8 +348,6 @@ func (c *Command) Run(args []string) int {
}
}

cfg.Partition = c.flagPartitionName

// Set up Consul client.
if c.consulClient == nil {
var err error
Expand Down Expand Up @@ -464,7 +461,7 @@ func (c *Command) Run(args []string) int {
MetricsConfig: metricsConfig,
InitContainerResources: initResources,
ConsulSidecarResources: consulSidecarResources,
ConsulPartition: c.flagPartitionName,
ConsulPartition: c.http.Partition(),
AllowK8sNamespacesSet: allowK8sNamespaces,
DenyK8sNamespacesSet: denyK8sNamespaces,
EnableNamespaces: c.flagEnableNamespaces,
Expand Down
2 changes: 1 addition & 1 deletion control-plane/subcommand/inject-connect/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestRun_FlagValidation(t *testing.T) {
},
{
flags: []string{"-consul-k8s-image", "foo", "-consul-image", "foo", "-envoy-image", "envoy:1.16.0",
"-partition-name", "default"},
"-partition", "default"},
expErr: "-enable-partitions must be set to 'true' if -partition-name is set",
},
{
Expand Down

0 comments on commit 7bf487f

Please sign in to comment.