Skip to content

Commit 6fad005

Browse files
kate-osbornbjee19salonichf5
authored
Add UpstreamSetttingsPolicy (#2941)
Problem: As a user, I want to be able to configure the upstream settings for a Service referenced by a HTTP or GRPCRoute. Solution: Add UpstreamSettingsPolicy CRD. This is a direct policy that can be attached to one or more Services. The Service must be referenced by an HTTP or GRPCRoute that is owned by the "winning" NGF Gateway. Co-authored-by: bjee19 <[email protected]> Co-authored-by: salonichf5 <[email protected]>
1 parent 938b7ff commit 6fad005

File tree

74 files changed

+5219
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5219
-554
lines changed

apis/v1alpha1/policy_methods.go

+12
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ func (p *ObservabilityPolicy) GetPolicyStatus() v1alpha2.PolicyStatus {
3131
func (p *ObservabilityPolicy) SetPolicyStatus(status v1alpha2.PolicyStatus) {
3232
p.Status = status
3333
}
34+
35+
func (p *UpstreamSettingsPolicy) GetTargetRefs() []v1alpha2.LocalPolicyTargetReference {
36+
return p.Spec.TargetRefs
37+
}
38+
39+
func (p *UpstreamSettingsPolicy) GetPolicyStatus() v1alpha2.PolicyStatus {
40+
return p.Status
41+
}
42+
43+
func (p *UpstreamSettingsPolicy) SetPolicyStatus(status v1alpha2.PolicyStatus) {
44+
p.Status = status
45+
}

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.

charts/nginx-gateway-fabric/templates/clusterrole.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ rules:
104104
- nginxproxies
105105
- clientsettingspolicies
106106
- observabilitypolicies
107+
- upstreamsettingspolicies
107108
{{- if .Values.nginxGateway.snippetsFilters.enable }}
108109
- snippetsfilters
109110
{{- end }}
@@ -116,6 +117,7 @@ rules:
116117
- nginxgateways/status
117118
- clientsettingspolicies/status
118119
- observabilitypolicies/status
120+
- upstreamsettingspolicies/status
119121
{{- if .Values.nginxGateway.snippetsFilters.enable }}
120122
- snippetsfilters/status
121123
{{- end }}

0 commit comments

Comments
 (0)