From ccddafbb8dde137cf8ddba535c2b96eb0afc56e7 Mon Sep 17 00:00:00 2001 From: dprotaso Date: Tue, 23 Jul 2024 09:50:44 -0400 Subject: [PATCH] preserve appropriate header matching when creating the virtualservice --- .../ingress/resources/virtual_service.go | 10 ++++------ .../ingress/resources/virtual_service_test.go | 14 +++++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/reconciler/ingress/resources/virtual_service.go b/pkg/reconciler/ingress/resources/virtual_service.go index d7bb2d1192..8a9f9d0635 100644 --- a/pkg/reconciler/ingress/resources/virtual_service.go +++ b/pkg/reconciler/ingress/resources/virtual_service.go @@ -260,16 +260,14 @@ func makeMatch(host, path string, headers map[string]v1alpha1.HeaderMatch, gatew } } + match.Headers = make(map[string]*istiov1beta1.StringMatch, len(headers)) for k, v := range headers { - match.Headers = map[string]*istiov1beta1.StringMatch{ - k: { - MatchType: &istiov1beta1.StringMatch_Exact{ - Exact: v.Exact, - }, + match.Headers[k] = &istiov1beta1.StringMatch{ + MatchType: &istiov1beta1.StringMatch_Exact{ + Exact: v.Exact, }, } } - return match } diff --git a/pkg/reconciler/ingress/resources/virtual_service_test.go b/pkg/reconciler/ingress/resources/virtual_service_test.go index 5dedfdf19a..43a7198e27 100644 --- a/pkg/reconciler/ingress/resources/virtual_service_test.go +++ b/pkg/reconciler/ingress/resources/virtual_service_test.go @@ -212,7 +212,6 @@ func TestMakeVirtualServices_CorrectMetadata(t *testing.T) { } func TestMakeVirtualServicesSpec_CorrectGateways(t *testing.T) { - tests := []struct { name string ingress *v1alpha1.Ingress @@ -640,6 +639,9 @@ func TestMakeVirtualServiceRoute_Vanilla(t *testing.T) { "my-header": { Exact: "my-header-value", }, + "my-second-header": { + Exact: "my-second-header-value", + }, }, Splits: []v1alpha1.IngressBackendSplit{{ IngressBackend: v1alpha1.IngressBackend{ @@ -664,6 +666,11 @@ func TestMakeVirtualServiceRoute_Vanilla(t *testing.T) { Exact: "my-header-value", }, }, + "my-second-header": { + MatchType: &istiov1beta1.StringMatch_Exact{ + Exact: "my-second-header-value", + }, + }, }, }, { Gateways: []string{"gateway-1"}, @@ -676,6 +683,11 @@ func TestMakeVirtualServiceRoute_Vanilla(t *testing.T) { Exact: "my-header-value", }, }, + "my-second-header": { + MatchType: &istiov1beta1.StringMatch_Exact{ + Exact: "my-second-header-value", + }, + }, }, }}, Route: []*istiov1beta1.HTTPRouteDestination{{