From b318753de55f95acab145552ab1b4ecb67308abf Mon Sep 17 00:00:00 2001 From: shaun-nx Date: Thu, 14 Aug 2025 08:40:10 +0100 Subject: [PATCH 1/6] Add tests for ObservabilityPolicy CEL validation --- tests/cel/common.go | 6 +- tests/cel/observabilitypolicy_test.go | 182 ++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 tests/cel/observabilitypolicy_test.go diff --git a/tests/cel/common.go b/tests/cel/common.go index fcbb85366c..b683925b69 100644 --- a/tests/cel/common.go +++ b/tests/cel/common.go @@ -33,7 +33,7 @@ const ( // ClientSettingsPolicy validation errors. const ( expectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute` - expectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.` + expectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io` expectedHeaderWithoutServerError = `header can only be specified if server is specified` ) @@ -44,6 +44,10 @@ const ( expectedMinReplicasLessThanOrEqualError = `minReplicas must be less than or equal to maxReplicas` ) +const ( + expectedTargetRefMustBeHTTPRouteOrGrpcRouteError = `TargetRef Kind must be: HTTPRoute or GRPCRoute` +) + const ( defaultNamespace = "default" ) diff --git a/tests/cel/observabilitypolicy_test.go b/tests/cel/observabilitypolicy_test.go new file mode 100644 index 0000000000..cdf14203a0 --- /dev/null +++ b/tests/cel/observabilitypolicy_test.go @@ -0,0 +1,182 @@ +package cel + +import ( + "testing" + + controllerruntime "sigs.k8s.io/controller-runtime" + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + + ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1" +) + +func TestObservabilityPoliciesTargetRefKind(t *testing.T) { + t.Parallel() + k8sClient := getKubernetesClient(t) + + tests := []struct { + spec ngfAPIv1alpha1.ObservabilityPolicySpec + name string + wantErrors []string + }{ + { + name: "Validate TargetRef of kind HTTPRoute is allowed", + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate TargetRef of kind GRPCRoute is allowed", + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: grpcRouteKind, + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate Invalid TargetRef Kind is not allowed", + wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: invalidKind, + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate TCPRoute TargetRef Kind is not allowed", + wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: tcpRouteKind, + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate TargetRef of kind Gateway is allowed", + wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: gatewayKind, + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate ObservabilityPolicy is applied when one TargetRef is valid and another is invalid", + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: gatewayKind, + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Group: gatewayGroup, + }, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + spec := tt.spec + + for i := range spec.TargetRefs { + spec.TargetRefs[i].Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) + } + + observabilityPolicy := &ngfAPIv1alpha1.ObservabilityPolicy{ + ObjectMeta: controllerruntime.ObjectMeta{ + Name: uniqueResourceName(testResourceName), + Namespace: defaultNamespace, + }, + Spec: spec, + } + validateCrd(t, tt.wantErrors, observabilityPolicy, k8sClient) + }) + } +} + +func TestObservabilityPoliciesTargetRefGroup(t *testing.T) { + t.Parallel() + k8sClient := getKubernetesClient(t) + + tests := []struct { + spec ngfAPIv1alpha1.ObservabilityPolicySpec + name string + wantErrors []string + }{ + { + name: "Validate gateway.networking.k8s.io TargetRef Group is allowed", + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate invalid.networking.k8s.io TargetRef Group is not allowed", + wantErrors: []string{expectedTargetRefGroupError}, + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Group: invalidGroup, + }, + }, + }, + }, + { + name: "Validate discovery.k8s.io/v1 TargetRef Group is not allowed", + wantErrors: []string{expectedTargetRefGroupError}, + spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Group: discoveryGroup, + }, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + spec := tt.spec + + for i := range spec.TargetRefs { + spec.TargetRefs[i].Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) + } + + observabilityPolicy := &ngfAPIv1alpha1.ObservabilityPolicy{ + ObjectMeta: controllerruntime.ObjectMeta{ + Name: uniqueResourceName(testResourceName), + Namespace: defaultNamespace, + }, + Spec: spec, + } + validateCrd(t, tt.wantErrors, observabilityPolicy, k8sClient) + }) + } +} From 6dac6fa8aa060112992e36f40a369d82e72417e3 Mon Sep 17 00:00:00 2001 From: shaun-nx Date: Thu, 14 Aug 2025 11:27:45 +0100 Subject: [PATCH 2/6] Add tests for TargetRef Kind and Name Combo --- tests/cel/common.go | 1 + tests/cel/observabilitypolicy_test.go | 75 ++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/tests/cel/common.go b/tests/cel/common.go index b683925b69..8b437cd881 100644 --- a/tests/cel/common.go +++ b/tests/cel/common.go @@ -46,6 +46,7 @@ const ( const ( expectedTargetRefMustBeHTTPRouteOrGrpcRouteError = `TargetRef Kind must be: HTTPRoute or GRPCRoute` + expectedTargetRefKindAndNameComboMustBeUnique = `TargetRef Kind and Name combination must be unique` ) const ( diff --git a/tests/cel/observabilitypolicy_test.go b/tests/cel/observabilitypolicy_test.go index cdf14203a0..3f9d4a50d8 100644 --- a/tests/cel/observabilitypolicy_test.go +++ b/tests/cel/observabilitypolicy_test.go @@ -6,7 +6,7 @@ import ( controllerruntime "sigs.k8s.io/controller-runtime" gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1" + ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2" ) func TestObservabilityPoliciesTargetRefKind(t *testing.T) { @@ -14,13 +14,13 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { k8sClient := getKubernetesClient(t) tests := []struct { - spec ngfAPIv1alpha1.ObservabilityPolicySpec + spec ngfAPIv1alpha2.ObservabilityPolicySpec name string wantErrors []string }{ { name: "Validate TargetRef of kind HTTPRoute is allowed", - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: httpRouteKind, @@ -31,7 +31,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { }, { name: "Validate TargetRef of kind GRPCRoute is allowed", - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: grpcRouteKind, @@ -43,7 +43,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { { name: "Validate Invalid TargetRef Kind is not allowed", wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: invalidKind, @@ -55,7 +55,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { { name: "Validate TCPRoute TargetRef Kind is not allowed", wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: tcpRouteKind, @@ -67,7 +67,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { { name: "Validate TargetRef of kind Gateway is allowed", wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: gatewayKind, @@ -78,7 +78,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { }, { name: "Validate ObservabilityPolicy is applied when one TargetRef is valid and another is invalid", - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: gatewayKind, @@ -102,7 +102,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { spec.TargetRefs[i].Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) } - observabilityPolicy := &ngfAPIv1alpha1.ObservabilityPolicy{ + observabilityPolicy := &ngfAPIv1alpha2.ObservabilityPolicy{ ObjectMeta: controllerruntime.ObjectMeta{ Name: uniqueResourceName(testResourceName), Namespace: defaultNamespace, @@ -119,13 +119,13 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) { k8sClient := getKubernetesClient(t) tests := []struct { - spec ngfAPIv1alpha1.ObservabilityPolicySpec + spec ngfAPIv1alpha2.ObservabilityPolicySpec name string wantErrors []string }{ { name: "Validate gateway.networking.k8s.io TargetRef Group is allowed", - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: httpRouteKind, @@ -137,7 +137,7 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) { { name: "Validate invalid.networking.k8s.io TargetRef Group is not allowed", wantErrors: []string{expectedTargetRefGroupError}, - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: httpRouteKind, @@ -149,7 +149,7 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) { { name: "Validate discovery.k8s.io/v1 TargetRef Group is not allowed", wantErrors: []string{expectedTargetRefGroupError}, - spec: ngfAPIv1alpha1.ObservabilityPolicySpec{ + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ { Kind: httpRouteKind, @@ -169,7 +169,54 @@ func TestObservabilityPoliciesTargetRefGroup(t *testing.T) { spec.TargetRefs[i].Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) } - observabilityPolicy := &ngfAPIv1alpha1.ObservabilityPolicy{ + observabilityPolicy := &ngfAPIv1alpha2.ObservabilityPolicy{ + ObjectMeta: controllerruntime.ObjectMeta{ + Name: uniqueResourceName(testResourceName), + Namespace: defaultNamespace, + }, + Spec: spec, + } + validateCrd(t, tt.wantErrors, observabilityPolicy, k8sClient) + }) + } +} + +func TestObservabilityPoliciesTargetRefKindAndNameCombo(t *testing.T) { + t.Parallel() + k8sClient := getKubernetesClient(t) + + tests := []struct { + spec ngfAPIv1alpha2.ObservabilityPolicySpec + name string + wantErrors []string + }{ + { + // This test is not throwing an error like we expect it to... + name: "Validate TargetRef Kind and Name combination is unique", + wantErrors: []string{expectedTargetRefKindAndNameComboMustBeUnique}, + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Name: gatewayv1alpha2.ObjectName(testTargetRefName), + Group: gatewayGroup, + }, + { + Kind: httpRouteKind, + Name: gatewayv1alpha2.ObjectName(testTargetRefName), + Group: gatewayGroup, + }, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + spec := tt.spec + + observabilityPolicy := &ngfAPIv1alpha2.ObservabilityPolicy{ ObjectMeta: controllerruntime.ObjectMeta{ Name: uniqueResourceName(testResourceName), Namespace: defaultNamespace, From 789910aec400b9b699b69e15af678b286f60755d Mon Sep 17 00:00:00 2001 From: shaun-nx Date: Thu, 14 Aug 2025 11:47:38 +0100 Subject: [PATCH 3/6] Add tests for tracing ratio strategy --- tests/cel/common.go | 2 + tests/cel/observabilitypolicy_test.go | 64 +++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tests/cel/common.go b/tests/cel/common.go index 8b437cd881..bf13290fc2 100644 --- a/tests/cel/common.go +++ b/tests/cel/common.go @@ -44,9 +44,11 @@ const ( expectedMinReplicasLessThanOrEqualError = `minReplicas must be less than or equal to maxReplicas` ) +// ObservabilityPolicy validation errors. const ( expectedTargetRefMustBeHTTPRouteOrGrpcRouteError = `TargetRef Kind must be: HTTPRoute or GRPCRoute` expectedTargetRefKindAndNameComboMustBeUnique = `TargetRef Kind and Name combination must be unique` + expectedStrategyMustBeOfTypeRatio = `ratio can only be specified if strategy is of type ratio` ) const ( diff --git a/tests/cel/observabilitypolicy_test.go b/tests/cel/observabilitypolicy_test.go index 3f9d4a50d8..9a8e6e0381 100644 --- a/tests/cel/observabilitypolicy_test.go +++ b/tests/cel/observabilitypolicy_test.go @@ -7,6 +7,7 @@ import ( gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers" ) func TestObservabilityPoliciesTargetRefKind(t *testing.T) { @@ -227,3 +228,66 @@ func TestObservabilityPoliciesTargetRefKindAndNameCombo(t *testing.T) { }) } } + +func TestObservabilityPoliciesTracing(t *testing.T) { + t.Parallel() + k8sClient := getKubernetesClient(t) + + tests := []struct { + spec ngfAPIv1alpha2.ObservabilityPolicySpec + name string + wantErrors []string + }{ + { + name: "Validate ObservabilityPolicy is applied when ratio is set and strategy is TraceStrategyRatio", + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Group: gatewayGroup, + }, + }, + Tracing: &ngfAPIv1alpha2.Tracing{ + Strategy: ngfAPIv1alpha2.TraceStrategyRatio, + Ratio: helpers.GetPointer[int32](50), + }, + }, + }, + { + name: "Validate ObservabilityPolicy is invalid when ratio is set and strategy is not TraceStrategyRatio", + wantErrors: []string{expectedStrategyMustBeOfTypeRatio}, + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Group: gatewayGroup, + }, + }, + Tracing: &ngfAPIv1alpha2.Tracing{ + Strategy: ngfAPIv1alpha2.TraceStrategyParent, + Ratio: helpers.GetPointer[int32](50), + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + spec := tt.spec + + for i := range spec.TargetRefs { + spec.TargetRefs[i].Name = gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)) + } + + observabilityPolicy := &ngfAPIv1alpha2.ObservabilityPolicy{ + ObjectMeta: controllerruntime.ObjectMeta{ + Name: uniqueResourceName(testResourceName), + Namespace: defaultNamespace, + }, + Spec: spec, + } + validateCrd(t, tt.wantErrors, observabilityPolicy, k8sClient) + }) + } +} From ddd027139f2e68ea3010f38c814c38ae5136a344 Mon Sep 17 00:00:00 2001 From: shaun-nx Date: Thu, 14 Aug 2025 11:56:14 +0100 Subject: [PATCH 4/6] Add additioanl test cases for `TestObservabilityPoliciesTargetRefKindAndNameCombo` --- tests/cel/observabilitypolicy_test.go | 39 ++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/cel/observabilitypolicy_test.go b/tests/cel/observabilitypolicy_test.go index 9a8e6e0381..ac6043da02 100644 --- a/tests/cel/observabilitypolicy_test.go +++ b/tests/cel/observabilitypolicy_test.go @@ -66,7 +66,7 @@ func TestObservabilityPoliciesTargetRefKind(t *testing.T) { }, }, { - name: "Validate TargetRef of kind Gateway is allowed", + name: "Validate TargetRef of kind Gateway is not allowed", wantErrors: []string{expectedTargetRefMustBeHTTPRouteOrGrpcRouteError}, spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ @@ -192,8 +192,7 @@ func TestObservabilityPoliciesTargetRefKindAndNameCombo(t *testing.T) { wantErrors []string }{ { - // This test is not throwing an error like we expect it to... - name: "Validate TargetRef Kind and Name combination is unique", + name: "Validate resource is invalid when TargetRef Kind and Name combination is not unique", wantErrors: []string{expectedTargetRefKindAndNameComboMustBeUnique}, spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ @@ -210,6 +209,40 @@ func TestObservabilityPoliciesTargetRefKindAndNameCombo(t *testing.T) { }, }, }, + { + name: "Validate resource is valid when TargetRef Kind and Name combination is unique using different kinds", + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Name: gatewayv1alpha2.ObjectName(testTargetRefName), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(testTargetRefName), + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate resource is valid when TargetRef Kind and Name combination is unique using different names", + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Name: gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)), + Group: gatewayGroup, + }, + }, + }, + }, } for _, tt := range tests { From 72568ad744e52ef33c37e02ee90ebf33dd4f1ca7 Mon Sep 17 00:00:00 2001 From: shaun-nx Date: Fri, 15 Aug 2025 10:03:05 +0100 Subject: [PATCH 5/6] Add additional test for multiple duplicate targetref --- tests/cel/observabilitypolicy_test.go | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/cel/observabilitypolicy_test.go b/tests/cel/observabilitypolicy_test.go index ac6043da02..c609243943 100644 --- a/tests/cel/observabilitypolicy_test.go +++ b/tests/cel/observabilitypolicy_test.go @@ -1,6 +1,7 @@ package cel import ( + "fmt" "testing" controllerruntime "sigs.k8s.io/controller-runtime" @@ -243,6 +244,57 @@ func TestObservabilityPoliciesTargetRefKindAndNameCombo(t *testing.T) { }, }, }, + { + name: "Validate three TargetRefs with one duplicate name are not allowed", + wantErrors: []string{expectedTargetRefKindAndNameComboMustBeUnique}, + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: httpRouteKind, + Name: gatewayv1alpha2.ObjectName(uniqueResourceName(testTargetRefName)), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(testTargetRefName), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(testTargetRefName), + Group: gatewayGroup, + }, + }, + }, + }, + { + name: "Validate multiple duplicate TargetRefs are not allowed", + wantErrors: []string{expectedTargetRefKindAndNameComboMustBeUnique}, + spec: ngfAPIv1alpha2.ObservabilityPolicySpec{ + TargetRefs: []gatewayv1alpha2.LocalPolicyTargetReference{ + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(fmt.Sprintf("duplicate-group-1-%s", testTargetRefName)), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(fmt.Sprintf("duplicate-group-1-%s", testTargetRefName)), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(fmt.Sprintf("duplicate-group-2-%s", testTargetRefName)), + Group: gatewayGroup, + }, + { + Kind: grpcRouteKind, + Name: gatewayv1alpha2.ObjectName(fmt.Sprintf("duplicate-group-2-%s", testTargetRefName)), + Group: gatewayGroup, + }, + }, + }, + }, } for _, tt := range tests { From 95e0c49550f056f7c48b5e672c2b45fa22f58dcf Mon Sep 17 00:00:00 2001 From: shaun-nx Date: Wed, 20 Aug 2025 10:11:39 +0100 Subject: [PATCH 6/6] Fix syntax error --- tests/cel/common.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cel/common.go b/tests/cel/common.go index ffaec4b88a..c906dce7ec 100644 --- a/tests/cel/common.go +++ b/tests/cel/common.go @@ -52,6 +52,7 @@ const ( expectedTargetRefMustBeHTTPRouteOrGrpcRouteError = `TargetRef Kind must be: HTTPRoute or GRPCRoute` expectedTargetRefKindAndNameComboMustBeUnique = `TargetRef Kind and Name combination must be unique` expectedStrategyMustBeOfTypeRatio = `ratio can only be specified if strategy is of type ratio` +) // UpstreamSettingsPolicy validation errors. const (