Skip to content

Commit 74c027a

Browse files
author
Kate Osborn
committed
Add CEL validation for target ref kind
1 parent 4268e3c commit 74c027a

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

apis/v1alpha1/clientsettingspolicy_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ type ClientSettingsPolicyList struct {
3838
type ClientSettingsPolicySpec struct {
3939
// TargetRef identifies an API object to apply the policy to.
4040
// Object must be in the same namespace as the policy.
41+
// Support: Gateway, HTTPRoute, GRPCRoute.
4142
//
42-
// Support: Gateway, HTTPRoute
43+
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute",rule="(self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')"
44+
//nolint:lll
4345
TargetRef gatewayv1alpha2.PolicyTargetReference `json:"targetRef"`
4446

4547
// Body defines the client request body settings.

config/crd/bases/gateway.nginx.org_clientsettingspolicies.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ spec:
116116
description: |-
117117
TargetRef identifies an API object to apply the policy to.
118118
Object must be in the same namespace as the policy.
119-
120-
121-
Support: Gateway, HTTPRoute
119+
Support: Gateway, HTTPRoute, GRPCRoute.
122120
properties:
123121
group:
124122
description: Group is the group of the target resource.
@@ -151,6 +149,10 @@ spec:
151149
- kind
152150
- name
153151
type: object
152+
x-kubernetes-validations:
153+
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
154+
GRPCRoute'
155+
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
154156
required:
155157
- targetRef
156158
type: object

deploy/crds.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ spec:
115115
description: |-
116116
TargetRef identifies an API object to apply the policy to.
117117
Object must be in the same namespace as the policy.
118-
119-
120-
Support: Gateway, HTTPRoute
118+
Support: Gateway, HTTPRoute, GRPCRoute.
121119
properties:
122120
group:
123121
description: Group is the group of the target resource.
@@ -150,6 +148,10 @@ spec:
150148
- kind
151149
- name
152150
type: object
151+
x-kubernetes-validations:
152+
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
153+
GRPCRoute'
154+
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
153155
required:
154156
- targetRef
155157
type: object

0 commit comments

Comments
 (0)