Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fe8b4dc

Browse files
bjee19Kate Osborn
authored and
Kate Osborn
committedNov 20, 2024
Add UpstreamSettingsPolicy CRD (#2515)
Problem: Users want to configure the behavior of the connection between NGINX and their upstream applications. Solution: Add the UpstreamSettingsPolicy CRD, which is a direct policy that will attach to a Service that is referenced in an HTTPRoute or GRPCRoute. Testing: Tested that validation works.
1 parent 9fb7b33 commit fe8b4dc

File tree

8 files changed

+965
-3
lines changed

8 files changed

+965
-3
lines changed
 

‎apis/v1alpha1/register.go

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
4242
&ClientSettingsPolicyList{},
4343
&SnippetsFilter{},
4444
&SnippetsFilterList{},
45+
&UpstreamSettingsPolicy{},
46+
&UpstreamSettingsPolicyList{},
4547
)
4648
// AddToGroupVersion allows the serialization of client types like ListOptions.
4749
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
// +genclient
9+
// +kubebuilder:object:root=true
10+
// +kubebuilder:storageversion
11+
// +kubebuilder:subresource:status
12+
// +kubebuilder:resource:categories=nginx-gateway-fabric,scope=Namespaced,shortName=uspolicy
13+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
14+
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
15+
16+
// UpstreamSettingsPolicy is a Direct Attached Policy. It provides a way to configure the behavior of
17+
// the connection between NGINX and the upstream applications.
18+
type UpstreamSettingsPolicy struct {
19+
metav1.TypeMeta `json:",inline"`
20+
metav1.ObjectMeta `json:"metadata,omitempty"`
21+
22+
// Spec defines the desired state of the UpstreamSettingsPolicy.
23+
Spec UpstreamSettingsPolicySpec `json:"spec"`
24+
25+
// Status defines the state of the UpstreamSettingsPolicy.
26+
Status gatewayv1alpha2.PolicyStatus `json:"status,omitempty"`
27+
}
28+
29+
// +kubebuilder:object:root=true
30+
31+
// UpstreamSettingsPolicyList contains a list of UpstreamSettingsPolicies.
32+
type UpstreamSettingsPolicyList struct {
33+
metav1.TypeMeta `json:",inline"`
34+
metav1.ListMeta `json:"metadata,omitempty"`
35+
Items []UpstreamSettingsPolicy `json:"items"`
36+
}
37+
38+
// UpstreamSettingsPolicySpec defines the desired state of the UpstreamSettingsPolicy.
39+
type UpstreamSettingsPolicySpec struct {
40+
// ZoneSize is the size of the shared memory zone used by the upstream. This memory zone is used to share
41+
// the upstream configuration between nginx worker processes. The more servers that an upstream has,
42+
// the larger memory zone is required.
43+
// Default: OSS: 512k, Plus: 1m.
44+
// Directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#zone
45+
//
46+
// +optional
47+
ZoneSize *Size `json:"zoneSize,omitempty"`
48+
49+
// KeepAlive defines the keep-alive settings.
50+
//
51+
// +optional
52+
KeepAlive *UpstreamKeepAlive `json:"keepAlive,omitempty"`
53+
54+
// TargetRefs identifies API object(s) to apply the policy to.
55+
// Objects must be in the same namespace as the policy.
56+
// Support: Service
57+
//
58+
// +kubebuilder:validation:MinItems=1
59+
// +kubebuilder:validation:MaxItems=16
60+
// +kubebuilder:validation:XValidation:message="TargetRefs Kind must be: Service",rule="self.all(t, t.kind=='Service')"
61+
// +kubebuilder:validation:XValidation:message="TargetRefs Group must be core",rule="self.exists(t, t.group=='') || self.exists(t, t.group=='core')"
62+
//nolint:lll
63+
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReference `json:"targetRefs"`
64+
}
65+
66+
// UpstreamKeepAlive defines the keep-alive settings for upstreams.
67+
type UpstreamKeepAlive struct {
68+
// Connections sets the maximum number of idle keep-alive connections to upstream servers that are preserved
69+
// in the cache of each nginx worker process. When this number is exceeded, the least recently used
70+
// connections are closed.
71+
// Directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
72+
//
73+
// +optional
74+
// +kubebuilder:validation:Minimum=1
75+
Connections *int32 `json:"connections,omitempty"`
76+
77+
// Requests sets the maximum number of requests that can be served through one keep-alive connection.
78+
// After the maximum number of requests are made, the connection is closed.
79+
// Directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive_requests
80+
//
81+
// +optional
82+
// +kubebuilder:validation:Minimum=0
83+
Requests *int32 `json:"requests,omitempty"`
84+
85+
// Time defines the maximum time during which requests can be processed through one keep-alive connection.
86+
// After this time is reached, the connection is closed following the subsequent request processing.
87+
// Directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive_time
88+
//
89+
// +optional
90+
Time *Duration `json:"time,omitempty"`
91+
92+
// Timeout defines the keep-alive timeout for upstreams.
93+
// Directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive_timeout
94+
//
95+
// +optional
96+
Timeout *Duration `json:"timeout,omitempty"`
97+
}

‎apis/v1alpha1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)
Please sign in to comment.