From 03c730389e9276617a7ced0725d9e5f90248ccba Mon Sep 17 00:00:00 2001 From: Maliz Date: Thu, 20 Apr 2023 14:34:21 -0700 Subject: [PATCH 1/8] add sameness group to exported services --- .../templates/crd-exportedservices.yaml | 3 + .../api/v1alpha1/exportedservices_types.go | 35 +++++-- .../v1alpha1/exportedservices_types_test.go | 94 +++++++++++++++++-- ...consul.hashicorp.com_exportedservices.yaml | 3 + control-plane/go.mod | 2 +- control-plane/go.sum | 2 + 6 files changed, 125 insertions(+), 14 deletions(-) diff --git a/charts/consul/templates/crd-exportedservices.yaml b/charts/consul/templates/crd-exportedservices.yaml index 007990372c..581ee39a6d 100644 --- a/charts/consul/templates/crd-exportedservices.yaml +++ b/charts/consul/templates/crd-exportedservices.yaml @@ -79,6 +79,9 @@ spec: description: '[Experimental] Peer is the name of the peer to export the service to.' type: string + samenessGroup: + description: SamenessGroup is the name of the sameness group to export the service to. + type: string type: object type: array name: diff --git a/control-plane/api/v1alpha1/exportedservices_types.go b/control-plane/api/v1alpha1/exportedservices_types.go index e4df1cee0d..04f93ec9c0 100644 --- a/control-plane/api/v1alpha1/exportedservices_types.go +++ b/control-plane/api/v1alpha1/exportedservices_types.go @@ -19,6 +19,7 @@ import ( ) const ExportedServicesKubeKind = "exportedservices" +const WildcardSpecifier = "*" func init() { SchemeBuilder.Register(&ExportedServices{}, &ExportedServicesList{}) @@ -73,6 +74,8 @@ type ServiceConsumer struct { Partition string `json:"partition,omitempty"` // [Experimental] Peer is the name of the peer to export the service to. Peer string `json:"peer,omitempty"` + // SamenessGroup is the name of the sameness group to export the service to. + SamenessGroup string `json:"samenessGroup,omitempty"` } func (in *ExportedServices) GetObjectMeta() metav1.ObjectMeta { @@ -169,8 +172,9 @@ func (in *ExportedService) toConsul() capi.ExportedService { var consumers []capi.ServiceConsumer for _, consumer := range in.Consumers { consumers = append(consumers, capi.ServiceConsumer{ - Partition: consumer.Partition, - Peer: consumer.Peer, + Partition: consumer.Partition, + Peer: consumer.Peer, + SamenessGroup: consumer.SamenessGroup, }) } return capi.ExportedService{ @@ -230,14 +234,31 @@ func (in *ExportedService) validate(path *field.Path, consulMeta common.ConsulMe } func (in *ServiceConsumer) validate(path *field.Path, consulMeta common.ConsulMeta) *field.Error { - if in.Partition != "" && in.Peer != "" { - return field.Invalid(path, *in, "both partition and peer cannot be specified.") + count := 0 + + if in.Partition != "" { + count++ + } + if in.Peer != "" { + count++ + } + if in.SamenessGroup != "" { + count++ } - if in.Partition == "" && in.Peer == "" { - return field.Invalid(path, *in, "either partition or peer must be specified.") + if count > 1 { + return field.Invalid(path, *in, "Service consumer must define at most one of Peer, Partition, or SamenessGroup") + } + if count == 0 { + return field.Invalid(path, *in, "Service consumer must define at least one of Peer, Partition, or SamenessGroup") } if !consulMeta.PartitionsEnabled && in.Partition != "" { - return field.Invalid(path.Child("partitions"), in.Partition, "Consul Admin Partitions need to be enabled to specify partition.") + return field.Invalid(path.Child("partition"), in.Partition, "Consul Admin Partitions need to be enabled to specify partition.") + } + if in.Partition == WildcardSpecifier { + return field.Invalid(path.Child("partition"), "", "exporting to all partitions (wildcard) is not supported") + } + if in.Peer == WildcardSpecifier { + return field.Invalid(path.Child("peer"), "", "exporting to all peers (wildcard) is not supported") } return nil } diff --git a/control-plane/api/v1alpha1/exportedservices_types_test.go b/control-plane/api/v1alpha1/exportedservices_types_test.go index e94eb36cbe..0854f5b138 100644 --- a/control-plane/api/v1alpha1/exportedservices_types_test.go +++ b/control-plane/api/v1alpha1/exportedservices_types_test.go @@ -59,6 +59,9 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { Peer: "second-peer", }, + { + SamenessGroup: "sg1", + }, }, }, { @@ -74,6 +77,9 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { Peer: "third-peer", }, + { + SamenessGroup: "sg2", + }, }, }, }, @@ -95,6 +101,9 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { Peer: "second-peer", }, + { + SamenessGroup: "sg1", + }, }, }, { @@ -110,6 +119,9 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { Peer: "third-peer", }, + { + SamenessGroup: "sg2", + }, }, }, }, @@ -183,6 +195,9 @@ func TestExportedServices_ToConsul(t *testing.T) { { Peer: "second-peer", }, + { + SamenessGroup: "sg2", + }, }, }, { @@ -198,6 +213,9 @@ func TestExportedServices_ToConsul(t *testing.T) { { Peer: "third-peer", }, + { + SamenessGroup: "sg3", + }, }, }, }, @@ -219,6 +237,9 @@ func TestExportedServices_ToConsul(t *testing.T) { { Peer: "second-peer", }, + { + SamenessGroup: "sg2", + }, }, }, { @@ -234,6 +255,9 @@ func TestExportedServices_ToConsul(t *testing.T) { { Peer: "third-peer", }, + { + SamenessGroup: "sg3", + }, }, }, }, @@ -278,6 +302,9 @@ func TestExportedServices_Validate(t *testing.T) { { Peer: "second-peer", }, + { + SamenessGroup: "sg2", + }, }, }, }, @@ -331,10 +358,10 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: true, expectedErrMsgs: []string{ - `spec.services[0].consumers[0]: Invalid value: v1alpha1.ServiceConsumer{Partition:"second", Peer:"second-peer"}: both partition and peer cannot be specified.`, + `Service consumer must define at most one of Peer, Partition, or SamenessGroup`, }, }, - "neither partition nor peer name specified": { + "none of peer, partition, or sameness group defined": { input: &ExportedServices{ ObjectMeta: metav1.ObjectMeta{ Name: common.DefaultConsulPartition, @@ -354,7 +381,7 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: true, expectedErrMsgs: []string{ - `spec.services[0].consumers[0]: Invalid value: v1alpha1.ServiceConsumer{Partition:"", Peer:""}: either partition or peer must be specified.`, + `Service consumer must define at least one of Peer, Partition, or SamenessGroup`, }, }, "partition provided when partitions are disabled": { @@ -379,7 +406,7 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: false, expectedErrMsgs: []string{ - `spec.services[0].consumers[0].partitions: Invalid value: "test-partition": Consul Admin Partitions need to be enabled to specify partition.`, + `spec.services[0].consumers[0].partition: Invalid value: "test-partition": Consul Admin Partitions need to be enabled to specify partition.`, }, }, "namespace provided when namespaces are disabled": { @@ -407,6 +434,56 @@ func TestExportedServices_Validate(t *testing.T) { `spec.services[0]: Invalid value: "frontend": Consul Namespaces must be enabled to specify service namespace.`, }, }, + "exporting to all partitions is not supported": { + input: &ExportedServices{ + ObjectMeta: metav1.ObjectMeta{ + Name: common.DefaultConsulPartition, + }, + Spec: ExportedServicesSpec{ + Services: []ExportedService{ + { + Name: "service-frontend", + Namespace: "frontend", + Consumers: []ServiceConsumer{ + { + Partition: "*", + }, + }, + }, + }, + }, + }, + namespaceEnabled: true, + partitionsEnabled: true, + expectedErrMsgs: []string{ + `exporting to all partitions (wildcard) is not supported`, + }, + }, + "exporting to all peers (wildcard) is not supported": { + input: &ExportedServices{ + ObjectMeta: metav1.ObjectMeta{ + Name: common.DefaultConsulPartition, + }, + Spec: ExportedServicesSpec{ + Services: []ExportedService{ + { + Name: "service-frontend", + Namespace: "frontend", + Consumers: []ServiceConsumer{ + { + Peer: "*", + }, + }, + }, + }, + }, + }, + namespaceEnabled: true, + partitionsEnabled: true, + expectedErrMsgs: []string{ + `exporting to all peers (wildcard) is not supported`, + }, + }, "multiple errors": { input: &ExportedServices{ ObjectMeta: metav1.ObjectMeta{ @@ -423,6 +500,10 @@ func TestExportedServices_Validate(t *testing.T) { Peer: "second-peer", }, {}, + { + SamenessGroup: "sg2", + Partition: "partition2", + }, }, }, }, @@ -431,8 +512,9 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: true, expectedErrMsgs: []string{ - `spec.services[0].consumers[0]: Invalid value: v1alpha1.ServiceConsumer{Partition:"second", Peer:"second-peer"}: both partition and peer cannot be specified.`, - `spec.services[0].consumers[1]: Invalid value: v1alpha1.ServiceConsumer{Partition:"", Peer:""}: either partition or peer must be specified.`, + `spec.services[0].consumers[0]: Invalid value: v1alpha1.ServiceConsumer{Partition:"second", Peer:"second-peer", SamenessGroup:""}: Service consumer must define at most one of Peer, Partition, or SamenessGroup`, + `spec.services[0].consumers[1]: Invalid value: v1alpha1.ServiceConsumer{Partition:"", Peer:"", SamenessGroup:""}: Service consumer must define at least one of Peer, Partition, or SamenessGroup`, + `spec.services[0].consumers[2]: Invalid value: v1alpha1.ServiceConsumer{Partition:"partition2", Peer:"", SamenessGroup:"sg2"}: Service consumer must define at most one of Peer, Partition, or SamenessGroup`, }, }, } diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml index 6352ac3af1..ae119fa71e 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml @@ -75,6 +75,9 @@ spec: description: '[Experimental] Peer is the name of the peer to export the service to.' type: string + samenessGroup: + description: SamenessGroup is the name of the sameness group to export the service to. + type: string type: object type: array name: diff --git a/control-plane/go.mod b/control-plane/go.mod index 23900deb46..88d62bfb75 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20220831174802-b8af65262de8 github.com/hashicorp/consul-server-connection-manager v0.1.0 - github.com/hashicorp/consul/api v1.10.1-0.20230331190547-fc64a702f43c + github.com/hashicorp/consul/api v1.10.1-0.20230418163148-eb9f671eafae github.com/hashicorp/consul/sdk v0.13.1 github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f github.com/hashicorp/go-hclog v1.2.2 diff --git a/control-plane/go.sum b/control-plane/go.sum index d794bad47f..b4959f818b 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -355,6 +355,8 @@ github.com/hashicorp/consul-server-connection-manager v0.1.0/go.mod h1:XVVlO+Yk7 github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.10.1-0.20230331190547-fc64a702f43c h1:MfDuWW38RozPodXT2aGc5jakoYo9EjgYpZl+vR3//Wg= github.com/hashicorp/consul/api v1.10.1-0.20230331190547-fc64a702f43c/go.mod h1:f8zVJwBcLdr1IQnfdfszjUM0xzp31Zl3bpws3pL9uFM= +github.com/hashicorp/consul/api v1.10.1-0.20230418163148-eb9f671eafae h1:lYnO52QxlfATRZ1Vo8tQV+lFns7rZ4iAbbi3JN4ZAQw= +github.com/hashicorp/consul/api v1.10.1-0.20230418163148-eb9f671eafae/go.mod h1:f8zVJwBcLdr1IQnfdfszjUM0xzp31Zl3bpws3pL9uFM= github.com/hashicorp/consul/proto-public v0.1.0 h1:O0LSmCqydZi363hsqc6n2v5sMz3usQMXZF6ziK3SzXU= github.com/hashicorp/consul/proto-public v0.1.0/go.mod h1:vs2KkuWwtjkIgA5ezp4YKPzQp4GitV+q/+PvksrA92k= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= From 02664c08984cdc6c5c883eb9c97d371a086d9fd7 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 09:41:45 -0700 Subject: [PATCH 2/8] update CRDs --- .../templates/crd-exportedservices.yaml | 3 ++- .../consul/templates/crd-proxydefaults.yaml | 5 +++-- .../consul/templates/crd-samenessgroups.yaml | 17 +++++++++++++--- .../templates/crd-serviceresolvers.yaml | 5 +++-- ...consul.hashicorp.com_exportedservices.yaml | 6 ++---- .../consul.hashicorp.com_ingressgateways.yaml | 3 --- .../bases/consul.hashicorp.com_meshes.yaml | 3 --- ...consul.hashicorp.com_peeringacceptors.yaml | 3 --- .../consul.hashicorp.com_peeringdialers.yaml | 3 --- .../consul.hashicorp.com_proxydefaults.yaml | 8 +++----- .../consul.hashicorp.com_samenessgroups.yaml | 20 +++++++++++++------ .../consul.hashicorp.com_servicedefaults.yaml | 3 --- ...onsul.hashicorp.com_serviceintentions.yaml | 3 --- ...consul.hashicorp.com_serviceresolvers.yaml | 8 +++----- .../consul.hashicorp.com_servicerouters.yaml | 3 --- ...consul.hashicorp.com_servicesplitters.yaml | 3 --- ...sul.hashicorp.com_terminatinggateways.yaml | 3 --- control-plane/config/webhook/manifests.yaml | 2 +- control-plane/go.mod | 4 ---- control-plane/go.sum | 2 -- 20 files changed, 45 insertions(+), 62 deletions(-) diff --git a/charts/consul/templates/crd-exportedservices.yaml b/charts/consul/templates/crd-exportedservices.yaml index 581ee39a6d..d3b263be81 100644 --- a/charts/consul/templates/crd-exportedservices.yaml +++ b/charts/consul/templates/crd-exportedservices.yaml @@ -80,7 +80,8 @@ spec: to export the service to.' type: string samenessGroup: - description: SamenessGroup is the name of the sameness group to export the service to. + description: SamenessGroup is the name of the sameness + group to export the service to. type: string type: object type: array diff --git a/charts/consul/templates/crd-proxydefaults.yaml b/charts/consul/templates/crd-proxydefaults.yaml index 6bb1234066..f72d1c7cea 100644 --- a/charts/consul/templates/crd-proxydefaults.yaml +++ b/charts/consul/templates/crd-proxydefaults.yaml @@ -153,8 +153,9 @@ spec: "sequential") and "order-by-locality". type: string regions: - description: The ordered list of the regions of the failover targets. - Valid values can be "us-west-1", "us-west-2", and so on. + description: Regions is the ordered list of the regions of the + failover targets. Valid values can be "us-west-1", "us-west-2", + and so on. items: type: string type: array diff --git a/charts/consul/templates/crd-samenessgroups.yaml b/charts/consul/templates/crd-samenessgroups.yaml index e541539481..60beb5662c 100644 --- a/charts/consul/templates/crd-samenessgroups.yaml +++ b/charts/consul/templates/crd-samenessgroups.yaml @@ -58,16 +58,27 @@ spec: description: SamenessGroupSpec defines the desired state of SamenessGroup. properties: defaultForFailover: - description: 'DefaultForFailover indicates that upstream requests to members of the given sameness group will implicitly failover between members of this sameness group.' + description: DefaultForFailover indicates that upstream requests to + members of the given sameness group will implicitly failover between + members of this sameness group. When DefaultForFailover is true, + the local partition must be a member of the sameness group or IncludeLocal + must be set to true. type: boolean includeLocal: - description: 'IncludeLocal is used to include the local partition as the first member of the sameness group.' + description: IncludeLocal is used to include the local partition as + the first member of the sameness group. The local partition can + only be a member of a single sameness group. type: boolean members: - description: 'Members are the partitions and peers that are part of the sameness group.' + description: Members are the partitions and peers that are part of + the sameness group. If a member of a sameness group does not exist, + it will be ignored. items: properties: partition: + description: The partitions and peers that are part of the sameness + group. A sameness group member cannot define both peer and + partition at the same time. type: string peer: type: string diff --git a/charts/consul/templates/crd-serviceresolvers.yaml b/charts/consul/templates/crd-serviceresolvers.yaml index 1942b79b8f..04d6dd9754 100644 --- a/charts/consul/templates/crd-serviceresolvers.yaml +++ b/charts/consul/templates/crd-serviceresolvers.yaml @@ -88,8 +88,9 @@ spec: to "sequential") and "order-by-locality". type: string regions: - description: The ordered list of the regions of the failover targets. - Valid values can be "us-west-1", "us-west-2", and so on. + description: Regions is the ordered list of the regions + of the failover targets. Valid values can be "us-west-1", + "us-west-2", and so on. items: type: string type: array diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml index ae119fa71e..b9c889e214 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -76,7 +73,8 @@ spec: to export the service to.' type: string samenessGroup: - description: SamenessGroup is the name of the sameness group to export the service to. + description: SamenessGroup is the name of the sameness + group to export the service to. type: string type: object type: array diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml index fd8ebc86ff..16ac322090 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml index 4850ad152e..7ad173afbf 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml index 50df179f04..e782ef472f 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml index 01e4363f14..d5103252a5 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml index c66b5fdd0f..f03fe41a09 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -149,8 +146,9 @@ spec: "sequential") and "order-by-locality". type: string regions: - description: The ordered list of the regions of the failover targets. - Valid values can be "us-west-1", "us-west-2", and so on. + description: Regions is the ordered list of the regions of the + failover targets. Valid values can be "us-west-1", "us-west-2", + and so on. items: type: string type: array diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml index 5efda1ffa2..94b39807ef 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -54,16 +51,27 @@ spec: description: SamenessGroupSpec defines the desired state of SamenessGroup. properties: defaultForFailover: - description: 'DefaultForFailover indicates that upstream requests to members of the given sameness group will implicitly failover between members of this sameness group.' + description: DefaultForFailover indicates that upstream requests to + members of the given sameness group will implicitly failover between + members of this sameness group. When DefaultForFailover is true, + the local partition must be a member of the sameness group or IncludeLocal + must be set to true. type: boolean includeLocal: - description: 'IncludeLocal is used to include the local partition as the first member of the sameness group.' + description: IncludeLocal is used to include the local partition as + the first member of the sameness group. The local partition can + only be a member of a single sameness group. type: boolean members: - description: 'Members are the partitions and peers that are part of the sameness group.' + description: Members are the partitions and peers that are part of + the sameness group. If a member of a sameness group does not exist, + it will be ignored. items: properties: partition: + description: The partitions and peers that are part of the sameness + group. A sameness group member cannot define both peer and + partition at the same time. type: string peer: type: string diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml index 7744a8fe7a..4f335a923d 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml index 8e186af1a7..a0cc7a6343 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml index 56b5e72014..e82ae93d02 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -84,8 +81,9 @@ spec: to "sequential") and "order-by-locality". type: string regions: - description: The ordered list of the regions of the failover targets. - Valid values can be "us-west-1", "us-west-2", and so on. + description: Regions is the ordered list of the regions + of the failover targets. Valid values can be "us-west-1", + "us-west-2", and so on. items: type: string type: array diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml index 5b9c9d3c1f..de071bd0ef 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml index aa2b592c94..df8bbbfbdf 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml index b465cd9494..8e6c449ef8 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml @@ -1,6 +1,3 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/webhook/manifests.yaml b/control-plane/config/webhook/manifests.yaml index f96d669544..663ace9d70 100644 --- a/control-plane/config/webhook/manifests.yaml +++ b/control-plane/config/webhook/manifests.yaml @@ -138,7 +138,7 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-v1alpha1-samenessgroup + path: /mutate-v1alpha1-samenessgroups failurePolicy: Fail name: mutate-samenessgroup.consul.hashicorp.com rules: diff --git a/control-plane/go.mod b/control-plane/go.mod index 88d62bfb75..5307056ce3 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -25,8 +25,6 @@ require ( github.com/mitchellh/cli v1.1.0 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/onsi/ginkgo v1.16.4 - github.com/onsi/gomega v1.17.0 github.com/stretchr/testify v1.7.2 go.uber.org/zap v1.19.0 golang.org/x/text v0.3.8 @@ -110,7 +108,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/oklog/run v1.0.0 // indirect github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c // indirect github.com/pierrec/lz4 v2.5.2+incompatible // indirect @@ -147,7 +144,6 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/resty.v1 v1.12.0 // indirect gopkg.in/square/go-jose.v2 v2.5.1 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.22.2 // indirect diff --git a/control-plane/go.sum b/control-plane/go.sum index b4959f818b..c045aba7bd 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -353,8 +353,6 @@ github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20220831174802-b8af6526 github.com/hashicorp/consul-server-connection-manager v0.1.0 h1:XCweGvMHzra88rYv2zxwwuUOjBUdcQmNKVrnQmt/muo= github.com/hashicorp/consul-server-connection-manager v0.1.0/go.mod h1:XVVlO+Yk7aiRpspiHZkrrFVn9BJIiOPnQIzqytPxGaU= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/api v1.10.1-0.20230331190547-fc64a702f43c h1:MfDuWW38RozPodXT2aGc5jakoYo9EjgYpZl+vR3//Wg= -github.com/hashicorp/consul/api v1.10.1-0.20230331190547-fc64a702f43c/go.mod h1:f8zVJwBcLdr1IQnfdfszjUM0xzp31Zl3bpws3pL9uFM= github.com/hashicorp/consul/api v1.10.1-0.20230418163148-eb9f671eafae h1:lYnO52QxlfATRZ1Vo8tQV+lFns7rZ4iAbbi3JN4ZAQw= github.com/hashicorp/consul/api v1.10.1-0.20230418163148-eb9f671eafae/go.mod h1:f8zVJwBcLdr1IQnfdfszjUM0xzp31Zl3bpws3pL9uFM= github.com/hashicorp/consul/proto-public v0.1.0 h1:O0LSmCqydZi363hsqc6n2v5sMz3usQMXZF6ziK3SzXU= From dcd69ccb43d6417cce5f0579eac9290581638266 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 09:55:44 -0700 Subject: [PATCH 3/8] update deep copy --- .../api/v1alpha1/exportedservices_types.go | 2 +- .../api/v1alpha1/zz_generated.deepcopy.go | 51 +++++++++++++------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/control-plane/api/v1alpha1/exportedservices_types.go b/control-plane/api/v1alpha1/exportedservices_types.go index 04f93ec9c0..6695ae1132 100644 --- a/control-plane/api/v1alpha1/exportedservices_types.go +++ b/control-plane/api/v1alpha1/exportedservices_types.go @@ -249,7 +249,7 @@ func (in *ServiceConsumer) validate(path *field.Path, consulMeta common.ConsulMe return field.Invalid(path, *in, "Service consumer must define at most one of Peer, Partition, or SamenessGroup") } if count == 0 { - return field.Invalid(path, *in, "Service consumer must define at least one of Peer, Partition, or SamenessGroup") + return field.Invalid(path, *in, "service consumer must define at least one of Peer, Partition, or SamenessGroup") } if !consulMeta.PartitionsEnabled && in.Partition != "" { return field.Invalid(path.Child("partition"), in.Partition, "Consul Admin Partitions need to be enabled to specify partition.") diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index f485b5c5f1..87d4bd9594 100644 --- a/control-plane/api/v1alpha1/zz_generated.deepcopy.go +++ b/control-plane/api/v1alpha1/zz_generated.deepcopy.go @@ -1324,21 +1324,6 @@ func (in *RingHashConfig) DeepCopy() *RingHashConfig { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SamenessGroupMember) DeepCopyInto(out *SamenessGroupMember) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SamenessGroupMember. -func (in *SamenessGroupMember) DeepCopy() *SamenessGroupMember { - if in == nil { - return nil - } - out := new(SamenessGroupMember) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SamenessGroup) DeepCopyInto(out *SamenessGroup) { *out = *in @@ -1348,7 +1333,7 @@ func (in *SamenessGroup) DeepCopyInto(out *SamenessGroup) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SamenessGroups. +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SamenessGroup. func (in *SamenessGroup) DeepCopy() *SamenessGroup { if in == nil { return nil @@ -1398,6 +1383,40 @@ func (in *SamenessGroupList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SamenessGroupMember) DeepCopyInto(out *SamenessGroupMember) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SamenessGroupMember. +func (in *SamenessGroupMember) DeepCopy() *SamenessGroupMember { + if in == nil { + return nil + } + out := new(SamenessGroupMember) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in SamenessGroupMembers) DeepCopyInto(out *SamenessGroupMembers) { + { + in := &in + *out = make(SamenessGroupMembers, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SamenessGroupMembers. +func (in SamenessGroupMembers) DeepCopy() SamenessGroupMembers { + if in == nil { + return nil + } + out := new(SamenessGroupMembers) + in.DeepCopyInto(out) + return *out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SamenessGroupSpec) DeepCopyInto(out *SamenessGroupSpec) { *out = *in From 7a34ad0df80a442f7237cd09fe3feed330f031c9 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 10:42:47 -0700 Subject: [PATCH 4/8] re add license line --- .../crd/bases/consul.hashicorp.com_exportedservices.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_ingressgateways.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_meshes.yaml | 3 +++ .../crd/bases/consul.hashicorp.com_peeringacceptors.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_peeringdialers.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_proxydefaults.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_samenessgroups.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_servicedefaults.yaml | 3 +++ .../crd/bases/consul.hashicorp.com_serviceintentions.yaml | 3 +++ .../crd/bases/consul.hashicorp.com_serviceresolvers.yaml | 3 +++ .../config/crd/bases/consul.hashicorp.com_servicerouters.yaml | 3 +++ .../crd/bases/consul.hashicorp.com_servicesplitters.yaml | 3 +++ .../crd/bases/consul.hashicorp.com_terminatinggateways.yaml | 3 +++ 13 files changed, 39 insertions(+) diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml index b9c889e214..2295724ca5 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml index 16ac322090..fd8ebc86ff 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_ingressgateways.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml index 7ad173afbf..4850ad152e 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_meshes.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml index e782ef472f..50df179f04 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_peeringacceptors.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml index d5103252a5..01e4363f14 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_peeringdialers.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml index f03fe41a09..86409d2de0 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_proxydefaults.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml index 94b39807ef..c71a211f63 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_samenessgroups.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml index 4f335a923d..7744a8fe7a 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicedefaults.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml index a0cc7a6343..8e186af1a7 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml index e82ae93d02..bae83ac7b9 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_serviceresolvers.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml index de071bd0ef..5b9c9d3c1f 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicerouters.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml index df8bbbfbdf..aa2b592c94 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_servicesplitters.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml index 8e6c449ef8..b465cd9494 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_terminatinggateways.yaml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition From 39a0d454ca54e8e3005263300b3e3af90d75df57 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 10:46:44 -0700 Subject: [PATCH 5/8] check if sameness group is wildcard --- .../api/v1alpha1/exportedservices_types.go | 3 +++ .../v1alpha1/exportedservices_types_test.go | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/control-plane/api/v1alpha1/exportedservices_types.go b/control-plane/api/v1alpha1/exportedservices_types.go index 6695ae1132..6c09805f01 100644 --- a/control-plane/api/v1alpha1/exportedservices_types.go +++ b/control-plane/api/v1alpha1/exportedservices_types.go @@ -260,6 +260,9 @@ func (in *ServiceConsumer) validate(path *field.Path, consulMeta common.ConsulMe if in.Peer == WildcardSpecifier { return field.Invalid(path.Child("peer"), "", "exporting to all peers (wildcard) is not supported") } + if in.SamenessGroup == WildcardSpecifier { + return field.Invalid(path.Child("samenessgroup"), "", "exporting to all sameness groups (wildcard) is not supported") + } return nil } diff --git a/control-plane/api/v1alpha1/exportedservices_types_test.go b/control-plane/api/v1alpha1/exportedservices_types_test.go index 0854f5b138..2d16767938 100644 --- a/control-plane/api/v1alpha1/exportedservices_types_test.go +++ b/control-plane/api/v1alpha1/exportedservices_types_test.go @@ -484,6 +484,31 @@ func TestExportedServices_Validate(t *testing.T) { `exporting to all peers (wildcard) is not supported`, }, }, + "exporting to all sameness groups (wildcard) is not supported": { + input: &ExportedServices{ + ObjectMeta: metav1.ObjectMeta{ + Name: common.DefaultConsulPartition, + }, + Spec: ExportedServicesSpec{ + Services: []ExportedService{ + { + Name: "service-frontend", + Namespace: "frontend", + Consumers: []ServiceConsumer{ + { + SamenessGroup: "*", + }, + }, + }, + }, + }, + }, + namespaceEnabled: true, + partitionsEnabled: true, + expectedErrMsgs: []string{ + `exporting to all sameness groups (wildcard) is not supported`, + }, + }, "multiple errors": { input: &ExportedServices{ ObjectMeta: metav1.ObjectMeta{ From 71886f15a654b3dc8b346e284cc2900ecda5d414 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 10:51:51 -0700 Subject: [PATCH 6/8] remove experimental tag on peering fields --- charts/consul/templates/crd-exportedservices.yaml | 3 +-- charts/consul/templates/crd-serviceintentions.yaml | 3 +-- control-plane/api/v1alpha1/exportedservices_types.go | 2 +- control-plane/api/v1alpha1/serviceintentions_types.go | 2 +- .../crd/bases/consul.hashicorp.com_exportedservices.yaml | 3 +-- .../crd/bases/consul.hashicorp.com_serviceintentions.yaml | 3 +-- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/charts/consul/templates/crd-exportedservices.yaml b/charts/consul/templates/crd-exportedservices.yaml index d3b263be81..073e081d0c 100644 --- a/charts/consul/templates/crd-exportedservices.yaml +++ b/charts/consul/templates/crd-exportedservices.yaml @@ -76,8 +76,7 @@ spec: the service to. type: string peer: - description: '[Experimental] Peer is the name of the peer - to export the service to.' + description: Peer is the name of the peer to export the service to. type: string samenessGroup: description: SamenessGroup is the name of the sameness diff --git a/charts/consul/templates/crd-serviceintentions.yaml b/charts/consul/templates/crd-serviceintentions.yaml index cdbb5413b0..ede8ae09b0 100644 --- a/charts/consul/templates/crd-serviceintentions.yaml +++ b/charts/consul/templates/crd-serviceintentions.yaml @@ -102,8 +102,7 @@ spec: description: Partition is the Admin Partition for the Name parameter. type: string peer: - description: '[Experimental] Peer is the peer name for the Name - parameter.' + description: Peer is the peer name for the Name parameter. type: string permissions: description: Permissions is the list of all additional L7 attributes diff --git a/control-plane/api/v1alpha1/exportedservices_types.go b/control-plane/api/v1alpha1/exportedservices_types.go index 6c09805f01..ac209f74ce 100644 --- a/control-plane/api/v1alpha1/exportedservices_types.go +++ b/control-plane/api/v1alpha1/exportedservices_types.go @@ -72,7 +72,7 @@ type ExportedService struct { type ServiceConsumer struct { // Partition is the admin partition to export the service to. Partition string `json:"partition,omitempty"` - // [Experimental] Peer is the name of the peer to export the service to. + // Peer is the name of the peer to export the service to. Peer string `json:"peer,omitempty"` // SamenessGroup is the name of the sameness group to export the service to. SamenessGroup string `json:"samenessGroup,omitempty"` diff --git a/control-plane/api/v1alpha1/serviceintentions_types.go b/control-plane/api/v1alpha1/serviceintentions_types.go index 82a5dcfdc8..a066b4e84f 100644 --- a/control-plane/api/v1alpha1/serviceintentions_types.go +++ b/control-plane/api/v1alpha1/serviceintentions_types.go @@ -81,7 +81,7 @@ type SourceIntention struct { Name string `json:"name,omitempty"` // Namespace is the namespace for the Name parameter. Namespace string `json:"namespace,omitempty"` - // [Experimental] Peer is the peer name for the Name parameter. + // Peer is the peer name for the Name parameter. Peer string `json:"peer,omitempty"` // Partition is the Admin Partition for the Name parameter. Partition string `json:"partition,omitempty"` diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml index 2295724ca5..84e523f50c 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_exportedservices.yaml @@ -72,8 +72,7 @@ spec: the service to. type: string peer: - description: '[Experimental] Peer is the name of the peer - to export the service to.' + description: Peer is the name of the peer to export the service to. type: string samenessGroup: description: SamenessGroup is the name of the sameness diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml index 8e186af1a7..3c80ea8933 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_serviceintentions.yaml @@ -98,8 +98,7 @@ spec: description: Partition is the Admin Partition for the Name parameter. type: string peer: - description: '[Experimental] Peer is the peer name for the Name - parameter.' + description: Peer is the peer name for the Name parameter. type: string permissions: description: Permissions is the list of all additional L7 attributes From e748820fe97acbfeef0223f644654a597cf366f8 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 11:26:21 -0700 Subject: [PATCH 7/8] update error message case --- control-plane/api/v1alpha1/exportedservices_types.go | 2 +- .../api/v1alpha1/exportedservices_types_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/control-plane/api/v1alpha1/exportedservices_types.go b/control-plane/api/v1alpha1/exportedservices_types.go index ac209f74ce..06d6ce30cf 100644 --- a/control-plane/api/v1alpha1/exportedservices_types.go +++ b/control-plane/api/v1alpha1/exportedservices_types.go @@ -246,7 +246,7 @@ func (in *ServiceConsumer) validate(path *field.Path, consulMeta common.ConsulMe count++ } if count > 1 { - return field.Invalid(path, *in, "Service consumer must define at most one of Peer, Partition, or SamenessGroup") + return field.Invalid(path, *in, "service consumer must define at most one of Peer, Partition, or SamenessGroup") } if count == 0 { return field.Invalid(path, *in, "service consumer must define at least one of Peer, Partition, or SamenessGroup") diff --git a/control-plane/api/v1alpha1/exportedservices_types_test.go b/control-plane/api/v1alpha1/exportedservices_types_test.go index 2d16767938..d759a6f270 100644 --- a/control-plane/api/v1alpha1/exportedservices_types_test.go +++ b/control-plane/api/v1alpha1/exportedservices_types_test.go @@ -358,7 +358,7 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: true, expectedErrMsgs: []string{ - `Service consumer must define at most one of Peer, Partition, or SamenessGroup`, + `service consumer must define at most one of Peer, Partition, or SamenessGroup`, }, }, "none of peer, partition, or sameness group defined": { @@ -381,7 +381,7 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: true, expectedErrMsgs: []string{ - `Service consumer must define at least one of Peer, Partition, or SamenessGroup`, + `service consumer must define at least one of Peer, Partition, or SamenessGroup`, }, }, "partition provided when partitions are disabled": { @@ -537,9 +537,9 @@ func TestExportedServices_Validate(t *testing.T) { namespaceEnabled: true, partitionsEnabled: true, expectedErrMsgs: []string{ - `spec.services[0].consumers[0]: Invalid value: v1alpha1.ServiceConsumer{Partition:"second", Peer:"second-peer", SamenessGroup:""}: Service consumer must define at most one of Peer, Partition, or SamenessGroup`, - `spec.services[0].consumers[1]: Invalid value: v1alpha1.ServiceConsumer{Partition:"", Peer:"", SamenessGroup:""}: Service consumer must define at least one of Peer, Partition, or SamenessGroup`, - `spec.services[0].consumers[2]: Invalid value: v1alpha1.ServiceConsumer{Partition:"partition2", Peer:"", SamenessGroup:"sg2"}: Service consumer must define at most one of Peer, Partition, or SamenessGroup`, + `spec.services[0].consumers[0]: Invalid value: v1alpha1.ServiceConsumer{Partition:"second", Peer:"second-peer", SamenessGroup:""}: service consumer must define at most one of Peer, Partition, or SamenessGroup`, + `spec.services[0].consumers[1]: Invalid value: v1alpha1.ServiceConsumer{Partition:"", Peer:"", SamenessGroup:""}: service consumer must define at least one of Peer, Partition, or SamenessGroup`, + `spec.services[0].consumers[2]: Invalid value: v1alpha1.ServiceConsumer{Partition:"partition2", Peer:"", SamenessGroup:"sg2"}: service consumer must define at most one of Peer, Partition, or SamenessGroup`, }, }, } From d465ae0c7fe6552d5bd64615bbfb46694fe3a953 Mon Sep 17 00:00:00 2001 From: Maliz Date: Fri, 21 Apr 2023 11:50:13 -0700 Subject: [PATCH 8/8] update error message case in webhook test --- control-plane/api/v1alpha1/exportedservices_webhook_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control-plane/api/v1alpha1/exportedservices_webhook_test.go b/control-plane/api/v1alpha1/exportedservices_webhook_test.go index 41476bd822..735f938825 100644 --- a/control-plane/api/v1alpha1/exportedservices_webhook_test.go +++ b/control-plane/api/v1alpha1/exportedservices_webhook_test.go @@ -123,7 +123,7 @@ func TestValidateExportedServices(t *testing.T) { Partition: "", }, expAllow: false, - expErrMessage: "exportedservices.consul.hashicorp.com \"default\" is invalid: spec.services[0].consumers[0].partitions: Invalid value: \"other\": Consul Admin Partitions need to be enabled to specify partition.", + expErrMessage: "exportedservices.consul.hashicorp.com \"default\" is invalid: spec.services[0].consumers[0].partition: Invalid value: \"other\": Consul Admin Partitions need to be enabled to specify partition.", }, "no services": { existingResources: []runtime.Object{},