Skip to content

Commit 4b7e914

Browse files
author
Kate Osborn
committed
Add CEL validation for target ref group
1 parent e6ea1bd commit 4b7e914

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

apis/v1alpha1/clientsettingspolicy_types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ type ClientSettingsPolicyList struct {
3636

3737
// ClientSettingsPolicySpec defines the desired state of ClientSettingsPolicy.
3838
type ClientSettingsPolicySpec struct {
39+
// TargetRef identifies an API object to apply the policy to.
40+
// Object must be in the same namespace as the policy.
41+
// Support: Gateway, HTTPRoute, GRPCRoute.
42+
//
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+
// +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io.",rule="(self.group=='gateway.networking.k8s.io')"
45+
//nolint:lll
46+
TargetRef gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRef"`
47+
3948
// Body defines the client request body settings.
4049
//
4150
// +optional
@@ -45,14 +54,6 @@ type ClientSettingsPolicySpec struct {
4554
//
4655
// +optional
4756
KeepAlive *ClientKeepAlive `json:"keepAlive,omitempty"`
48-
49-
// TargetRef identifies an API object to apply the policy to.
50-
// Object must be in the same namespace as the policy.
51-
// Support: Gateway, HTTPRoute, GRPCRoute.
52-
//
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
55-
TargetRef gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRef"`
5657
}
5758

5859
// ClientBody contains the settings for the client request body.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ spec:
143143
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
144144
GRPCRoute'
145145
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
146+
- message: TargetRef Group must be gateway.networking.k8s.io.
147+
rule: (self.group=='gateway.networking.k8s.io')
146148
required:
147149
- targetRef
148150
type: object

deploy/crds.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ spec:
142142
- message: 'TargetRef Kind must be one of: Gateway, HTTPRoute, or
143143
GRPCRoute'
144144
rule: (self.kind=='Gateway' || self.kind=='HTTPRoute' || self.kind=='GRPCRoute')
145+
- message: TargetRef Group must be gateway.networking.k8s.io.
146+
rule: (self.group=='gateway.networking.k8s.io')
145147
required:
146148
- targetRef
147149
type: object

0 commit comments

Comments
 (0)