Skip to content

Commit e6ea1bd

Browse files
author
Kate Osborn
committed
Add CEL validation for target ref kind
1 parent f3938cf commit e6ea1bd

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
@@ -48,8 +48,10 @@ type ClientSettingsPolicySpec struct {
4848

4949
// TargetRef identifies an API object to apply the policy to.
5050
// Object must be in the same namespace as the policy.
51+
// Support: Gateway, HTTPRoute, GRPCRoute.
5152
//
52-
// Support: Gateway, HTTPRoute
53+
// +kubebuilder:validation:XValidation:message="TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute",rule="(self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')"
54+
//nolint:lll
5355
TargetRef gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRef"`
5456
}
5557

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.
@@ -141,6 +139,10 @@ spec:
141139
- kind
142140
- name
143141
type: object
142+
x-kubernetes-validations:
143+
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
144+
GRPCRoute'
145+
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
144146
required:
145147
- targetRef
146148
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.
@@ -140,6 +138,10 @@ spec:
140138
- kind
141139
- name
142140
type: object
141+
x-kubernetes-validations:
142+
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
143+
GRPCRoute'
144+
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
143145
required:
144146
- targetRef
145147
type: object

0 commit comments

Comments
 (0)