Skip to content

Commit 8181386

Browse files
authored
Add ProxySettingPolicy API and CRDs (#4266)
* Add ProxySettingPolicy API and CRDs * Add missing field comments * Add in CEL validation for TargetRefs * Move size type; remove duplicates strings; regen crds * Update the proposal to reflect the implemented API
1 parent e150378 commit 8181386

File tree

10 files changed

+1236
-99
lines changed

10 files changed

+1236
-99
lines changed

apis/v1alpha1/clientsettingspolicy_types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,3 @@ type ClientKeepAliveTimeout struct {
121121
// +optional
122122
Header *Duration `json:"header,omitempty"`
123123
}
124-
125-
// Size is a string value representing a size. Size can be specified in bytes, kilobytes (k), megabytes (m),
126-
// or gigabytes (g).
127-
// Examples: 1024, 8k, 1m.
128-
//
129-
// +kubebuilder:validation:Pattern=`^\d{1,4}(k|m|g)?$`
130-
type Size string

apis/v1alpha1/policy_methods.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ func (p *ClientSettingsPolicy) SetPolicyStatus(status gatewayv1.PolicyStatus) {
2020
p.Status = status
2121
}
2222

23+
func (p *ProxySettingsPolicy) GetTargetRefs() []gatewayv1.LocalPolicyTargetReference {
24+
return p.Spec.TargetRefs
25+
}
26+
27+
func (p *ProxySettingsPolicy) GetPolicyStatus() gatewayv1.PolicyStatus {
28+
return p.Status
29+
}
30+
31+
func (p *ProxySettingsPolicy) SetPolicyStatus(status gatewayv1.PolicyStatus) {
32+
p.Status = status
33+
}
34+
2335
func (p *UpstreamSettingsPolicy) GetTargetRefs() []gatewayv1.LocalPolicyTargetReference {
2436
return p.Spec.TargetRefs
2537
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
6+
)
7+
8+
// +genclient
9+
// +kubebuilder:object:root=true
10+
// +kubebuilder:storageversion
11+
// +kubebuilder:subresource:status
12+
// +kubebuilder:resource:categories=nginx-gateway-fabric,shortName=pspolicy
13+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
14+
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=inherited"
15+
16+
// ProxySettingsPolicy is an Inherited Attached Policy. It provides a way to configure the behavior of the connection
17+
// between NGINX Gateway Fabric and the upstream applications (backends).
18+
type ProxySettingsPolicy struct {
19+
metav1.TypeMeta `json:",inline"`
20+
metav1.ObjectMeta `json:"metadata,omitempty"`
21+
22+
// Spec defines the desired state of the ProxySettingsPolicy.
23+
Spec ProxySettingsPolicySpec `json:"spec"`
24+
25+
// Status defines the state of the ProxySettingsPolicy.
26+
Status gatewayv1.PolicyStatus `json:"status,omitempty"`
27+
}
28+
29+
// +kubebuilder:object:root=true
30+
31+
// ProxySettingsPolicyList contains a list of ProxySettingsPolicies.
32+
type ProxySettingsPolicyList struct {
33+
metav1.TypeMeta `json:",inline"`
34+
metav1.ListMeta `json:"metadata,omitempty"`
35+
Items []ProxySettingsPolicy `json:"items"`
36+
}
37+
38+
// ProxySettingsPolicySpec defines the desired state of the ProxySettingsPolicy.
39+
type ProxySettingsPolicySpec struct {
40+
// Buffering configures the buffering of responses from the proxied server.
41+
//
42+
// +optional
43+
Buffering *ProxyBuffering `json:"buffering,omitempty"`
44+
45+
// TargetRefs identifies the API object(s) to apply the policy to.
46+
// Objects must be in the same namespace as the policy.
47+
// Support: Gateway, HTTPRoute, GRPCRoute
48+
//
49+
// +kubebuilder:validation:MinItems=1
50+
// +kubebuilder:validation:MaxItems=16
51+
// +kubebuilder:validation:XValidation:message="TargetRefs entries must have kind Gateway, HTTPRoute, or GRPCRoute",rule="self.all(t, t.kind == 'Gateway' || t.kind == 'HTTPRoute' || t.kind == 'GRPCRoute')"
52+
// +kubebuilder:validation:XValidation:message="TargetRefs entries must have group gateway.networking.k8s.io",rule="self.all(t, t.group == 'gateway.networking.k8s.io')"
53+
// +kubebuilder:validation:XValidation:message="TargetRefs must be unique",rule="self.all(t1, self.exists_one(t2, t1.group == t2.group && t1.kind == t2.kind && t1.name == t2.name))"
54+
//nolint:lll
55+
TargetRefs []gatewayv1.LocalPolicyTargetReference `json:"targetRefs"`
56+
}
57+
58+
// ProxyBuffering contains the settings for proxy buffering.
59+
type ProxyBuffering struct {
60+
// Disable enables or disables buffering of responses from the proxied server.
61+
// If Disable is true, buffering is disabled. If Disable is false, or if Disable is not set, buffering is enabled.
62+
// Directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering
63+
//
64+
// +optional
65+
Disable *bool `json:"disable,omitempty"`
66+
67+
// BufferSize sets the size of the buffer used for reading the first part of the response received from
68+
// the proxied server. This part usually contains a small response header.
69+
// Directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size
70+
//
71+
// +optional
72+
BufferSize *Size `json:"bufferSize,omitempty"`
73+
74+
// Buffers sets the number and size of buffers used for reading a response from the proxied server,
75+
// for a single connection.
76+
// Directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffers
77+
//
78+
// +optional
79+
Buffers *ProxyBuffers `json:"buffers,omitempty"`
80+
81+
// BusyBuffersSize sets the total size of buffers that can be busy sending a response to the client,
82+
// while the response is not yet fully read.
83+
// Directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_busy_buffers_size
84+
//
85+
// +optional
86+
BusyBuffersSize *Size `json:"busyBuffersSize,omitempty"`
87+
}
88+
89+
// ProxyBuffers defines the number and size of the proxy buffers.
90+
type ProxyBuffers struct {
91+
// Size sets the size of each buffer.
92+
Size Size `json:"size"`
93+
94+
// Number sets the number of buffers.
95+
//
96+
// +kubebuilder:validation:Minimum=2
97+
// +kubebuilder:validation:Maximum=256
98+
Number int32 `json:"number"`
99+
}

apis/v1alpha1/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
3636
&NginxGatewayList{},
3737
&ClientSettingsPolicy{},
3838
&ClientSettingsPolicyList{},
39+
&ProxySettingsPolicy{},
40+
&ProxySettingsPolicyList{},
3941
&SnippetsFilter{},
4042
&SnippetsFilterList{},
4143
&UpstreamSettingsPolicy{},

apis/v1alpha1/shared_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ type SpanAttribute struct {
2626
// +kubebuilder:validation:Pattern=`^([^"$\\]|\\[^$])*$`
2727
Value string `json:"value"`
2828
}
29+
30+
// Size is a string value representing a size. Size can be specified in bytes, kilobytes (k), megabytes (m),
31+
// or gigabytes (g).
32+
// Examples: 1024, 8k, 1m.
33+
//
34+
// +kubebuilder:validation:Pattern=`^\d{1,4}(k|m|g)?$`
35+
type Size string

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)