diff --git a/.circleci/config.yml b/.circleci/config.yml index e7435d7449..f4da6ac895 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/charts/consul/templates/connect-inject-deployment.yaml b/charts/consul/templates/connect-inject-deployment.yaml index ed7266d7ee..f3f9f9a754 100644 --- a/charts/consul/templates/connect-inject-deployment.yaml +++ b/charts/consul/templates/connect-inject-deployment.yaml @@ -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 \ diff --git a/charts/consul/test/unit/connect-inject-deployment.bats b/charts/consul/test/unit/connect-inject-deployment.bats index 8d78e0fdc7..75df185d3f 100755 --- a/charts/consul/test/unit/connect-inject-deployment.bats +++ b/charts/consul/test/unit/connect-inject-deployment.bats @@ -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 \ diff --git a/control-plane/api/v1alpha1/ingressgateway_types.go b/control-plane/api/v1alpha1/ingressgateway_types.go index 6813b51f35..4dbe4cc03a 100644 --- a/control-plane/api/v1alpha1/ingressgateway_types.go +++ b/control-plane/api/v1alpha1/ingressgateway_types.go @@ -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 { diff --git a/control-plane/api/v1alpha1/mesh_types.go b/control-plane/api/v1alpha1/mesh_types.go index c637c1a783..671da5c8e7 100644 --- a/control-plane/api/v1alpha1/mesh_types.go +++ b/control-plane/api/v1alpha1/mesh_types.go @@ -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 { diff --git a/control-plane/api/v1alpha1/proxydefaults_types.go b/control-plane/api/v1alpha1/proxydefaults_types.go index bf4024eafa..a296962d11 100644 --- a/control-plane/api/v1alpha1/proxydefaults_types.go +++ b/control-plane/api/v1alpha1/proxydefaults_types.go @@ -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)) } diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index 8ad227b671..339f7ff32d 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -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)) } diff --git a/control-plane/api/v1alpha1/serviceintentions_types.go b/control-plane/api/v1alpha1/serviceintentions_types.go index 4a9aba6eca..50dcb98476 100644 --- a/control-plane/api/v1alpha1/serviceintentions_types.go +++ b/control-plane/api/v1alpha1/serviceintentions_types.go @@ -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(), diff --git a/control-plane/api/v1alpha1/serviceresolver_types.go b/control-plane/api/v1alpha1/serviceresolver_types.go index d606cfdf30..ef8f69db2e 100644 --- a/control-plane/api/v1alpha1/serviceresolver_types.go +++ b/control-plane/api/v1alpha1/serviceresolver_types.go @@ -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 { diff --git a/control-plane/api/v1alpha1/servicerouter_types.go b/control-plane/api/v1alpha1/servicerouter_types.go index a1a86d7b80..a6077fff7f 100644 --- a/control-plane/api/v1alpha1/servicerouter_types.go +++ b/control-plane/api/v1alpha1/servicerouter_types.go @@ -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 { diff --git a/control-plane/api/v1alpha1/servicesplitter_types.go b/control-plane/api/v1alpha1/servicesplitter_types.go index 45e0e7cb66..97b9e65237 100644 --- a/control-plane/api/v1alpha1/servicesplitter_types.go +++ b/control-plane/api/v1alpha1/servicesplitter_types.go @@ -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 { diff --git a/control-plane/api/v1alpha1/terminatinggateway_types.go b/control-plane/api/v1alpha1/terminatinggateway_types.go index d8138b1a42..18ede3b47d 100644 --- a/control-plane/api/v1alpha1/terminatinggateway_types.go +++ b/control-plane/api/v1alpha1/terminatinggateway_types.go @@ -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 { diff --git a/control-plane/connect-inject/endpoints_controller_ent_test.go b/control-plane/connect-inject/endpoints_controller_ent_test.go index 1ab5cfe254..4b75426346 100644 --- a/control-plane/connect-inject/endpoints_controller_ent_test.go +++ b/control-plane/connect-inject/endpoints_controller_ent_test.go @@ -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...))) } } @@ -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...))) } } diff --git a/control-plane/connect-inject/endpoints_controller_test.go b/control-plane/connect-inject/endpoints_controller_test.go index 229a8618fd..5f1a0dadd8 100644 --- a/control-plane/connect-inject/endpoints_controller_test.go +++ b/control-plane/connect-inject/endpoints_controller_test.go @@ -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 { @@ -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") } @@ -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...))) } } @@ -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...))) } } diff --git a/control-plane/go.mod b/control-plane/go.mod index adaedabaef..cf90cff87d 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -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 diff --git a/control-plane/go.sum b/control-plane/go.sum index 7a0487c1db..73b2ec8e4e 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -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= diff --git a/control-plane/subcommand/connect-init/command.go b/control-plane/subcommand/connect-init/command.go index a131f77024..d8158b5f20 100644 --- a/control-plane/subcommand/connect-init/command.go +++ b/control-plane/subcommand/connect-init/command.go @@ -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. @@ -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") @@ -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) diff --git a/control-plane/subcommand/connect-init/command_ent_test.go b/control-plane/subcommand/connect-init/command_ent_test.go index 010d325794..83f456cb2e 100644 --- a/control-plane/subcommand/connect-init/command_ent_test.go +++ b/control-plane/subcommand/connect-init/command_ent_test.go @@ -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. diff --git a/control-plane/subcommand/controller/command.go b/control-plane/subcommand/controller/command.go index 1e574d539f..0e7a84a540 100644 --- a/control-plane/subcommand/controller/command.go +++ b/control-plane/subcommand/controller/command.go @@ -32,7 +32,6 @@ type Command struct { flagEnableLeaderElection bool flagEnableWebhooks bool flagDatacenter string - flagPartition string flagLogLevel string flagLogJSON bool @@ -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", diff --git a/control-plane/subcommand/flags/http.go b/control-plane/subcommand/flags/http.go index b88acafcfd..090ef3bad1 100644 --- a/control-plane/subcommand/flags/http.go +++ b/control-plane/subcommand/flags/http.go @@ -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 } @@ -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() diff --git a/control-plane/subcommand/flags/usage_test.go b/control-plane/subcommand/flags/usage_test.go index 0b9c4793c9..2cf18ed166 100644 --- a/control-plane/subcommand/flags/usage_test.go +++ b/control-plane/subcommand/flags/usage_test.go @@ -47,6 +47,10 @@ HTTP API Options can also be set to HTTPS by setting the environment variable CONSUL_HTTP_SSL=true. + -partition= + [Enterprise Only] Name of the Consul Admin Partition to query. + Default to "default" if Admin Partitions are enabled. + -tls-server-name= The server name to use as the SNI host when connecting via TLS. This can also be specified via the CONSUL_TLS_SERVER_NAME diff --git a/control-plane/subcommand/inject-connect/command.go b/control-plane/subcommand/inject-connect/command.go index 1495c8d7c0..e93e07a48e 100644 --- a/control-plane/subcommand/inject-connect/command.go +++ b/control-plane/subcommand/inject-connect/command.go @@ -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 @@ -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 --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", @@ -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. @@ -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 @@ -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, diff --git a/control-plane/subcommand/inject-connect/command_test.go b/control-plane/subcommand/inject-connect/command_test.go index a0417a9079..88dcd20768 100644 --- a/control-plane/subcommand/inject-connect/command_test.go +++ b/control-plane/subcommand/inject-connect/command_test.go @@ -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", }, {