Skip to content

Commit be9eae3

Browse files
author
Kate Osborn
committed
Add ClientSettingsPolicy API
1 parent 2a40b2a commit be9eae3

7 files changed

+830
-25
lines changed
+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
6+
)
7+
8+
// +kubebuilder:object:root=true
9+
// +kubebuilder:storageversion
10+
// +kubebuilder:subresource:status
11+
// +kubebuilder:resource:categories=nginx-gateway-fabric,shortName=cspolicy
12+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
13+
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=inherited"
14+
15+
// ClientSettingsPolicy is an Inherited Attached Policy. It provides a way to configure the behavior of the connection
16+
// between the client and NGINX Gateway Fabric.
17+
type ClientSettingsPolicy struct {
18+
metav1.TypeMeta `json:",inline"`
19+
metav1.ObjectMeta `json:"metadata,omitempty"`
20+
21+
// Spec defines the desired state of the ClientSettingsPolicy.
22+
Spec ClientSettingsPolicySpec `json:"spec"`
23+
24+
// Status defines the state of the ClientSettingsPolicy.
25+
Status gatewayv1alpha2.PolicyStatus `json:"status,omitempty"`
26+
}
27+
28+
// +kubebuilder:object:root=true
29+
30+
// ClientSettingsPolicyList contains a list of ClientSettingsPolicies.
31+
type ClientSettingsPolicyList struct {
32+
metav1.TypeMeta `json:",inline"`
33+
metav1.ListMeta `json:"metadata,omitempty"`
34+
Items []ClientSettingsPolicy `json:"items"`
35+
}
36+
37+
// ClientSettingsPolicySpec defines the desired state of ClientSettingsPolicy.
38+
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+
//
42+
// Support: Gateway, HTTPRoute
43+
TargetRef gatewayv1alpha2.PolicyTargetReference `json:"targetRef"`
44+
45+
// Body defines the client request body settings.
46+
//
47+
// +optional
48+
Body *ClientBody `json:"body,omitempty"`
49+
50+
// KeepAlive defines the keep-alive settings.
51+
//
52+
// +optional
53+
KeepAlive *ClientKeepAlive `json:"keepAlive,omitempty"`
54+
}
55+
56+
// ClientBody contains the settings for the client request body.
57+
type ClientBody struct {
58+
// MaxSize sets the maximum allowed size of the client request body.
59+
// If the size in a request exceeds the configured value,
60+
// the 413 (Request Entity Too Large) error is returned to the client.
61+
// Setting size to 0 disables checking of client request body size.
62+
// Default: https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size.
63+
//
64+
// +optional
65+
MaxSize *Size `json:"maxSize,omitempty"`
66+
67+
// Timeout defines a timeout for reading client request body. The timeout is set only for a period between
68+
// two successive read operations, not for the transmission of the whole request body.
69+
// If a client does not transmit anything within this time, the request is terminated with the
70+
// 408 (Request Time-out) error.
71+
// Default: https://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_timeout.
72+
//
73+
// +optional
74+
Timeout *Duration `json:"timeout,omitempty"`
75+
}
76+
77+
// ClientKeepAlive defines the keep-alive settings for clients.
78+
type ClientKeepAlive struct {
79+
// Requests sets the maximum number of requests that can be served through one keep-alive connection.
80+
// After the maximum number of requests are made, the connection is closed. Closing connections periodically
81+
// is necessary to free per-connection memory allocations. Therefore, using too high maximum number of requests
82+
// is not recommended as it can lead to excessive memory usage.
83+
// Default: https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_requests.
84+
//
85+
// +optional
86+
// +kubebuilder:validation:Minimum=0
87+
Requests *int32 `json:"requests,omitempty"`
88+
89+
// Time defines the maximum time during which requests can be processed through one keep-alive connection.
90+
// After this time is reached, the connection is closed following the subsequent request processing.
91+
// Default: https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_time.
92+
//
93+
// +optional
94+
Time *Duration `json:"time,omitempty"`
95+
96+
// Timeout defines the keep-alive timeouts for clients.
97+
//
98+
// +optional
99+
Timeout *ClientKeepAliveTimeout `json:"timeout,omitempty"`
100+
}
101+
102+
// ClientKeepAliveTimeout defines the timeouts related to keep-alive client connections.
103+
// Default: Default: https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout.
104+
type ClientKeepAliveTimeout struct {
105+
// Server sets the timeout during which a keep-alive client connection will stay open on the server side.
106+
// Setting this value to 0 disables keep-alive client connections.
107+
//
108+
// +optional
109+
Server *Duration `json:"server,omitempty"`
110+
111+
// Header sets the timeout in the "Keep-Alive: timeout=time" response header field.
112+
//
113+
// +optional
114+
Header *Duration `json:"header,omitempty"`
115+
}
116+
117+
// Duration is a string value representing a duration in time.
118+
// Duration can be specified in milliseconds (ms) or seconds (s) A value without a suffix is seconds.
119+
// Examples: 120s, 50ms.
120+
//
121+
// +kubebuilder:validation:Pattern=`^\d{1,4}(ms|s)?$`
122+
type Duration string
123+
124+
// Size is a string value representing a size. Size can be specified in bytes, kilobytes (k), megabytes (m),
125+
// or gigabytes (g).
126+
// Examples: 1024, 8k, 1m.
127+
//
128+
// +kubebuilder:validation:Pattern=`^\d{1,4}(k|m|g)?$`
129+
type Size string

apis/v1alpha1/nginxgateway_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55
// +kubebuilder:object:root=true
66
// +kubebuilder:storageversion
77
// +kubebuilder:subresource:status
8+
// +kubebuilder:resource:categories=nginx-gateway-fabric
9+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
810

911
// NginxGateway represents the dynamic configuration for an NGINX Gateway Fabric control plane.
1012
type NginxGateway struct {

apis/v1alpha1/register.go

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
3434
scheme.AddKnownTypes(SchemeGroupVersion,
3535
&NginxGateway{},
3636
&NginxGatewayList{},
37+
&ClientSettingsPolicy{},
38+
&ClientSettingsPolicyList{},
3739
)
3840
// AddToGroupVersion allows the serialization of client types like ListOptions.
3941
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

apis/v1alpha1/zz_generated.deepcopy.go

+165
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)