From b44a7b73a32599e17a14039725b7d1abe7d9fd24 Mon Sep 17 00:00:00 2001 From: Ashwin Venkatesh Date: Wed, 29 Nov 2023 13:38:38 -0500 Subject: [PATCH 1/2] Update MatchesConsul to normalize partitions during comparison. --- .changelog/3284.txt | 3 +++ .../api/v1alpha1/exportedservices_types.go | 12 +++++++++-- .../v1alpha1/exportedservices_types_test.go | 7 ++++++- .../api/v1alpha1/ingressgateway_types.go | 18 +++++++++++++--- .../api/v1alpha1/ingressgateway_types_test.go | 4 ++-- .../api/v1alpha1/samenessgroup_types.go | 13 +++++++++--- .../api/v1alpha1/samenessgroup_types_test.go | 12 ++++++++--- .../api/v1alpha1/servicedefaults_types.go | 14 +++++++++++-- .../v1alpha1/servicedefaults_types_test.go | 4 ++-- .../api/v1alpha1/serviceresolver_types.go | 21 +++++++++++++++++-- .../v1alpha1/serviceresolver_types_test.go | 6 +++++- .../api/v1alpha1/servicerouter_types.go | 17 ++++++++++++--- .../api/v1alpha1/servicerouter_types_test.go | 4 +++- .../api/v1alpha1/servicesplitter_types.go | 15 +++++++++++-- .../v1alpha1/servicesplitter_types_test.go | 4 +++- 15 files changed, 126 insertions(+), 28 deletions(-) create mode 100644 .changelog/3284.txt diff --git a/.changelog/3284.txt b/.changelog/3284.txt new file mode 100644 index 0000000000..07b896f906 --- /dev/null +++ b/.changelog/3284.txt @@ -0,0 +1,3 @@ +```release-note:bug-fix +control-plane: normalize the `partition` and `namespace` fields in V1 CRDs when comparing with saved version of the config-entry. +``` diff --git a/control-plane/api/v1alpha1/exportedservices_types.go b/control-plane/api/v1alpha1/exportedservices_types.go index 06d6ce30cf..bcbb5e07d0 100644 --- a/control-plane/api/v1alpha1/exportedservices_types.go +++ b/control-plane/api/v1alpha1/exportedservices_types.go @@ -8,7 +8,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/hashicorp/consul-k8s/control-plane/api/common" "github.com/hashicorp/consul/api" capi "github.com/hashicorp/consul/api" corev1 "k8s.io/api/core/v1" @@ -16,6 +15,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) const ExportedServicesKubeKind = "exportedservices" @@ -189,8 +190,15 @@ func (in *ExportedServices) MatchesConsul(candidate api.ConfigEntry) bool { if !ok { return false } + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Services.Consumers.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + } + // 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.ExportedServicesConfigEntry{}, "Partition", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty()) + return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ExportedServicesConfigEntry{}, "Partition", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(), specialEquality) } diff --git a/control-plane/api/v1alpha1/exportedservices_types_test.go b/control-plane/api/v1alpha1/exportedservices_types_test.go index d759a6f270..0ee85b2c00 100644 --- a/control-plane/api/v1alpha1/exportedservices_types_test.go +++ b/control-plane/api/v1alpha1/exportedservices_types_test.go @@ -7,11 +7,12 @@ import ( "testing" "time" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) // Test MatchesConsul for cases that should return true. @@ -62,6 +63,7 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { SamenessGroup: "sg1", }, + {}, }, }, { @@ -104,6 +106,9 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { SamenessGroup: "sg1", }, + { + Partition: "default", + }, }, }, { diff --git a/control-plane/api/v1alpha1/ingressgateway_types.go b/control-plane/api/v1alpha1/ingressgateway_types.go index c781ab8cc8..23ea9515b3 100644 --- a/control-plane/api/v1alpha1/ingressgateway_types.go +++ b/control-plane/api/v1alpha1/ingressgateway_types.go @@ -6,16 +6,18 @@ package v1alpha1 import ( "encoding/json" "fmt" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/hashicorp/consul-k8s/control-plane/api/common" - "github.com/hashicorp/consul-k8s/control-plane/namespaces" capi "github.com/hashicorp/consul/api" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" + "github.com/hashicorp/consul-k8s/control-plane/namespaces" ) const ( @@ -268,8 +270,18 @@ func (in *IngressGateway) MatchesConsul(candidate capi.ConfigEntry) bool { if !ok { return false } + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Listeners.Services.Namespace" + }, cmp.Transformer("NormalizeNamespace", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Listeners.Services.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + } + // 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{}, "Partition", "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(), specialEquality) } func (in *IngressGateway) Validate(consulMeta common.ConsulMeta) error { diff --git a/control-plane/api/v1alpha1/ingressgateway_types_test.go b/control-plane/api/v1alpha1/ingressgateway_types_test.go index 73b53f5fff..9250d4b0c6 100644 --- a/control-plane/api/v1alpha1/ingressgateway_types_test.go +++ b/control-plane/api/v1alpha1/ingressgateway_types_test.go @@ -8,12 +8,13 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) func TestIngressGateway_MatchesConsul(t *testing.T) { @@ -102,7 +103,6 @@ func TestIngressGateway_MatchesConsul(t *testing.T) { Name: "name1", Hosts: []string{"host1_1", "host1_2"}, Namespace: "ns1", - Partition: "default", IngressServiceConfig: IngressServiceConfig{ MaxConnections: &maxConnections, MaxPendingRequests: &maxPendingRequests, diff --git a/control-plane/api/v1alpha1/samenessgroup_types.go b/control-plane/api/v1alpha1/samenessgroup_types.go index 86b02445f6..2b5dbd372f 100644 --- a/control-plane/api/v1alpha1/samenessgroup_types.go +++ b/control-plane/api/v1alpha1/samenessgroup_types.go @@ -5,9 +5,9 @@ package v1alpha1 import ( "encoding/json" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/hashicorp/consul-k8s/control-plane/api/common" "github.com/hashicorp/consul/api" capi "github.com/hashicorp/consul/api" corev1 "k8s.io/api/core/v1" @@ -15,6 +15,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) const ( @@ -166,8 +168,13 @@ func (in *SamenessGroup) MatchesConsul(candidate api.ConfigEntry) bool { if !ok { return false } - return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.SamenessGroupConfigEntry{}, "Partition", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(), - cmp.Comparer(transparentProxyConfigComparer)) + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Members.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + } + return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.SamenessGroupConfigEntry{}, "Partition", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(), specialEquality) } func (in *SamenessGroup) Validate(consulMeta common.ConsulMeta) error { diff --git a/control-plane/api/v1alpha1/samenessgroup_types_test.go b/control-plane/api/v1alpha1/samenessgroup_types_test.go index 0f461701cc..e7c473156b 100644 --- a/control-plane/api/v1alpha1/samenessgroup_types_test.go +++ b/control-plane/api/v1alpha1/samenessgroup_types_test.go @@ -4,13 +4,15 @@ package v1alpha1 import ( - "github.com/hashicorp/consul-k8s/control-plane/api/common" + "testing" + "time" + capi "github.com/hashicorp/consul/api" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "testing" - "time" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) func TestSamenessGroups_ToConsul(t *testing.T) { @@ -120,6 +122,7 @@ func TestSamenessGroups_MatchesConsul(t *testing.T) { { Partition: "p2", }, + {}, }, }, }, @@ -139,6 +142,9 @@ func TestSamenessGroups_MatchesConsul(t *testing.T) { { Partition: "p2", }, + { + Partition: "default", + }, }, }, true, diff --git a/control-plane/api/v1alpha1/servicedefaults_types.go b/control-plane/api/v1alpha1/servicedefaults_types.go index fd764b32b2..904154f184 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types.go +++ b/control-plane/api/v1alpha1/servicedefaults_types.go @@ -703,9 +703,19 @@ func (in *ServiceDefaults) MatchesConsul(candidate capi.ConfigEntry) bool { if !ok { return false } + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "UpstreamConfig.Overrides.Namespace" + }, cmp.Transformer("NormalizeNamespace", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "UpstreamConfig.Overrides.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + cmp.Comparer(transparentProxyConfigComparer), + } + // 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{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(), - cmp.Comparer(transparentProxyConfigComparer)) + return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceConfigEntry{}, "Partition", "Namespace", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty(), specialEquality) } func (in *ServiceDefaults) ConsulGlobalResource() bool { diff --git a/control-plane/api/v1alpha1/servicedefaults_types_test.go b/control-plane/api/v1alpha1/servicedefaults_types_test.go index 2292e55791..7cfe606385 100644 --- a/control-plane/api/v1alpha1/servicedefaults_types_test.go +++ b/control-plane/api/v1alpha1/servicedefaults_types_test.go @@ -565,7 +565,6 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { }, { Name: "upstream-default", - Namespace: "ns", EnvoyListenerJSON: `{"key": "value"}`, EnvoyClusterJSON: `{"key": "value"}`, Protocol: "http2", @@ -707,7 +706,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) { }, { Name: "upstream-default", - Namespace: "ns", + Namespace: "default", + Partition: "default", EnvoyListenerJSON: `{"key": "value"}`, EnvoyClusterJSON: `{"key": "value"}`, Protocol: "http2", diff --git a/control-plane/api/v1alpha1/serviceresolver_types.go b/control-plane/api/v1alpha1/serviceresolver_types.go index 3a8e907222..645cc23ac1 100644 --- a/control-plane/api/v1alpha1/serviceresolver_types.go +++ b/control-plane/api/v1alpha1/serviceresolver_types.go @@ -15,9 +15,10 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" "github.com/hashicorp/go-bexpr" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) const ServiceResolverKubeKind string = "serviceresolver" @@ -325,8 +326,24 @@ func (in *ServiceResolver) MatchesConsul(candidate capi.ConfigEntry) bool { if !ok { return false } + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Redirect.Namespace" + }, cmp.Transformer("NormalizeNamespace", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Redirect.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Failover.Targets.Namespace" + }, cmp.Transformer("NormalizeNamespace", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Failover.Targets.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + } + // 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{}, "Partition", "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(), specialEquality) } func (in *ServiceResolver) ConsulGlobalResource() bool { diff --git a/control-plane/api/v1alpha1/serviceresolver_types_test.go b/control-plane/api/v1alpha1/serviceresolver_types_test.go index 3fbc2b4fce..cd66fc9f16 100644 --- a/control-plane/api/v1alpha1/serviceresolver_types_test.go +++ b/control-plane/api/v1alpha1/serviceresolver_types_test.go @@ -8,12 +8,13 @@ import ( "testing" "time" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) func TestServiceResolver_MatchesConsul(t *testing.T) { @@ -63,6 +64,7 @@ func TestServiceResolver_MatchesConsul(t *testing.T) { Service: "redirect", ServiceSubset: "redirect_subset", Namespace: "redirect_namespace", + Partition: "default", Datacenter: "redirect_datacenter", Peer: "redirect_peer", }, @@ -96,6 +98,7 @@ func TestServiceResolver_MatchesConsul(t *testing.T) { Targets: []ServiceResolverFailoverTarget{ {Peer: "failover_peer3"}, {Partition: "failover_partition3", Namespace: "failover_namespace3"}, + {Partition: "default", Namespace: "default"}, }, Policy: &FailoverPolicy{ Mode: "order-by-locality", @@ -181,6 +184,7 @@ func TestServiceResolver_MatchesConsul(t *testing.T) { Targets: []capi.ServiceResolverFailoverTarget{ {Peer: "failover_peer3"}, {Partition: "failover_partition3", Namespace: "failover_namespace3"}, + {}, }, Policy: &capi.ServiceResolverFailoverPolicy{ Mode: "order-by-locality", diff --git a/control-plane/api/v1alpha1/servicerouter_types.go b/control-plane/api/v1alpha1/servicerouter_types.go index 43e7353bf5..b322d13134 100644 --- a/control-plane/api/v1alpha1/servicerouter_types.go +++ b/control-plane/api/v1alpha1/servicerouter_types.go @@ -8,14 +8,15 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/hashicorp/consul-k8s/control-plane/api/common" - "github.com/hashicorp/consul-k8s/control-plane/namespaces" capi "github.com/hashicorp/consul/api" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" + "github.com/hashicorp/consul-k8s/control-plane/namespaces" ) func init() { @@ -253,8 +254,18 @@ func (in *ServiceRouter) MatchesConsul(candidate capi.ConfigEntry) bool { if !ok { return false } + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Routes.Destination.Namespace" + }, cmp.Transformer("NormalizeNamespace", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Routes.Destination.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + } + // 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{}, "Partition", "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(), specialEquality) } func (in *ServiceRouter) Validate(consulMeta common.ConsulMeta) error { diff --git a/control-plane/api/v1alpha1/servicerouter_types_test.go b/control-plane/api/v1alpha1/servicerouter_types_test.go index 653bdc26c1..97d8e2b81a 100644 --- a/control-plane/api/v1alpha1/servicerouter_types_test.go +++ b/control-plane/api/v1alpha1/servicerouter_types_test.go @@ -8,11 +8,12 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) // Test MatchesConsul. @@ -158,6 +159,7 @@ func TestServiceRouter_MatchesConsul(t *testing.T) { Service: "service", ServiceSubset: "serviceSubset", Namespace: "namespace", + Partition: "default", PrefixRewrite: "prefixRewrite", IdleTimeout: 1 * time.Second, RequestTimeout: 1 * time.Second, diff --git a/control-plane/api/v1alpha1/servicesplitter_types.go b/control-plane/api/v1alpha1/servicesplitter_types.go index d94dbb7120..99ded7324a 100644 --- a/control-plane/api/v1alpha1/servicesplitter_types.go +++ b/control-plane/api/v1alpha1/servicesplitter_types.go @@ -9,13 +9,14 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) func init() { @@ -168,8 +169,18 @@ func (in *ServiceSplitter) MatchesConsul(candidate capi.ConfigEntry) bool { if !ok { return false } + + specialEquality := cmp.Options{ + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Splits.Namespace" + }, cmp.Transformer("NormalizeNamespace", normalizeEmptyToDefault)), + cmp.FilterPath(func(path cmp.Path) bool { + return path.String() == "Splits.Partition" + }, cmp.Transformer("NormalizePartition", normalizeEmptyToDefault)), + } + // 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{}, "Partition", "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(), specialEquality) } func (in *ServiceSplitter) Validate(consulMeta common.ConsulMeta) error { diff --git a/control-plane/api/v1alpha1/servicesplitter_types_test.go b/control-plane/api/v1alpha1/servicesplitter_types_test.go index e2ade99f1c..c5ab83becc 100644 --- a/control-plane/api/v1alpha1/servicesplitter_types_test.go +++ b/control-plane/api/v1alpha1/servicesplitter_types_test.go @@ -7,11 +7,12 @@ import ( "testing" "time" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/hashicorp/consul-k8s/control-plane/api/common" ) // Test MatchesConsul. @@ -96,6 +97,7 @@ func TestServiceSplitter_MatchesConsul(t *testing.T) { Service: "foo", ServiceSubset: "bar", Namespace: "baz", + Partition: "default", RequestHeaders: &capi.HTTPHeaderModifiers{ Add: map[string]string{ "foo": "bar", From 0e60896b927118e1db79e67d84a52dd8b61fc3ad Mon Sep 17 00:00:00 2001 From: Ashwin Venkatesh Date: Thu, 30 Nov 2023 12:49:05 -0500 Subject: [PATCH 2/2] Update test cases with valid datasets --- control-plane/api/v1alpha1/exportedservices_types_test.go | 5 +---- control-plane/api/v1alpha1/samenessgroup_types_test.go | 5 ++++- control-plane/api/v1alpha1/serviceresolver_types_test.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/control-plane/api/v1alpha1/exportedservices_types_test.go b/control-plane/api/v1alpha1/exportedservices_types_test.go index 0ee85b2c00..c9f2b66aa8 100644 --- a/control-plane/api/v1alpha1/exportedservices_types_test.go +++ b/control-plane/api/v1alpha1/exportedservices_types_test.go @@ -63,7 +63,6 @@ func TestExportedServices_MatchesConsul(t *testing.T) { { SamenessGroup: "sg1", }, - {}, }, }, { @@ -105,9 +104,7 @@ func TestExportedServices_MatchesConsul(t *testing.T) { }, { SamenessGroup: "sg1", - }, - { - Partition: "default", + Partition: "default", }, }, }, diff --git a/control-plane/api/v1alpha1/samenessgroup_types_test.go b/control-plane/api/v1alpha1/samenessgroup_types_test.go index e7c473156b..976f9c8db7 100644 --- a/control-plane/api/v1alpha1/samenessgroup_types_test.go +++ b/control-plane/api/v1alpha1/samenessgroup_types_test.go @@ -122,7 +122,9 @@ func TestSamenessGroups_MatchesConsul(t *testing.T) { { Partition: "p2", }, - {}, + { + Peer: "test-peer", + }, }, }, }, @@ -143,6 +145,7 @@ func TestSamenessGroups_MatchesConsul(t *testing.T) { Partition: "p2", }, { + Peer: "test-peer", Partition: "default", }, }, diff --git a/control-plane/api/v1alpha1/serviceresolver_types_test.go b/control-plane/api/v1alpha1/serviceresolver_types_test.go index cd66fc9f16..2070bd9df3 100644 --- a/control-plane/api/v1alpha1/serviceresolver_types_test.go +++ b/control-plane/api/v1alpha1/serviceresolver_types_test.go @@ -98,7 +98,7 @@ func TestServiceResolver_MatchesConsul(t *testing.T) { Targets: []ServiceResolverFailoverTarget{ {Peer: "failover_peer3"}, {Partition: "failover_partition3", Namespace: "failover_namespace3"}, - {Partition: "default", Namespace: "default"}, + {Peer: "failover_peer4"}, }, Policy: &FailoverPolicy{ Mode: "order-by-locality", @@ -184,7 +184,7 @@ func TestServiceResolver_MatchesConsul(t *testing.T) { Targets: []capi.ServiceResolverFailoverTarget{ {Peer: "failover_peer3"}, {Partition: "failover_partition3", Namespace: "failover_namespace3"}, - {}, + {Peer: "failover_peer4", Partition: "default", Namespace: "default"}, }, Policy: &capi.ServiceResolverFailoverPolicy{ Mode: "order-by-locality",