This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 279
/
upstreamtrafficsetting.go
241 lines (204 loc) · 8.85 KB
/
upstreamtrafficsetting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// UpstreamTrafficSetting defines the settings applicable to traffic destined
// to an upstream host.
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type UpstreamTrafficSetting struct {
// Object's type metadata
metav1.TypeMeta `json:",inline"`
// Object's metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec is the UpstreamTrafficSetting policy specification
// +optional
Spec UpstreamTrafficSettingSpec `json:"spec,omitempty"`
// Status is the status of the UpstreamTrafficSetting resource.
// +optional
Status UpstreamTrafficSettingStatus `json:"status,omitempty"`
}
// UpstreamTrafficSettingSpec defines the upstream traffic setting specification.
type UpstreamTrafficSettingSpec struct {
// Host the upstream traffic is directed to.
// Must either be an FQDN corresponding to the upstream service
// or the name of the upstream service. If only the service name
// is specified, the FQDN is derived from the service name and
// the namespace of the UpstreamTrafficSetting rule.
Host string `json:"host"`
// ConnectionSettings specifies the connection settings for traffic
// directed to the upstream host.
// +optional
ConnectionSettings *ConnectionSettingsSpec `json:"connectionSettings,omitempty"`
// RateLimit specifies the rate limit settings for the traffic
// directed to the upstream host.
// If HTTP rate limiting is specified, the rate limiting is applied
// at the VirtualHost level applicable to all routes within the
// VirtualHost.
// +optional
RateLimit *RateLimitSpec `json:"rateLimit,omitempty"`
// HTTPRoutes defines the list of HTTP routes settings
// for the upstream host. Settings are applied at a per
// route level.
// +optional
HTTPRoutes []HTTPRouteSpec `json:"httpRoutes,omitempty"`
}
// ConnectionSettingsSpec defines the connection settings for an
// upstream host.
type ConnectionSettingsSpec struct {
// TCP specifies the TCP level connection settings.
// Applies to both TCP and HTTP connections.
// +optional
TCP *TCPConnectionSettings `json:"tcp,omitempty"`
// HTTP specifies the HTTP level connection settings.
// +optional
HTTP *HTTPConnectionSettings `json:"http,omitempty"`
}
// TCPConnectionSettings defines the TCP connection settings for an
// upstream host.
type TCPConnectionSettings struct {
// MaxConnections specifies the maximum number of TCP connections
// allowed to the upstream host.
// Defaults to 4294967295 (2^32 - 1) if not specified.
// +optional
MaxConnections *uint32 `json:"maxConnections,omitempty"`
// ConnectTimeout specifies the TCP connection timeout.
// Defaults to 5s if not specified.
// +optional
ConnectTimeout *metav1.Duration `json:"connectTimeout,omitempty"`
}
// HTTPConnectionSettings defines the HTTP connection settings for an
// upstream host.
type HTTPConnectionSettings struct {
// MaxRequests specifies the maximum number of parallel requests
// allowed to the upstream host.
// Defaults to 4294967295 (2^32 - 1) if not specified.
// +optional
MaxRequests *uint32 `json:"maxRequests,omitempty"`
// MaxRequestsPerConnection specifies the maximum number of requests
// per connection allowed to the upstream host.
// Defaults to unlimited if not specified.
// +optional
MaxRequestsPerConnection *uint32 `json:"maxRequestsPerConnection,omitempty"`
// MaxPendingRequests specifies the maximum number of pending HTTP
// requests allowed to the upstream host. For HTTP/2 connections,
// if `maxRequestsPerConnection` is not configured, all requests will
// be multiplexed over the same connection so this circuit breaker
// will only be hit when no connection is already established.
// Defaults to 4294967295 (2^32 - 1) if not specified.
// +optional
MaxPendingRequests *uint32 `json:"maxPendingRequests,omitempty"`
// MaxRetries specifies the maximum number of parallel retries
// allowed to the upstream host.
// Defaults to 4294967295 (2^32 - 1) if not specified.
// +optional
MaxRetries *uint32 `json:"maxRetries,omitempty"`
}
// RateLimitSpec defines the rate limiting specification for
// the upstream host.
type RateLimitSpec struct {
// Local specified the local rate limiting specification
// for the upstream host.
// Local rate limiting is enforced directly by the upstream
// host without any involvement of a global rate limiting service.
// This is applied as a token bucket rate limiter.
// +optional
Local *LocalRateLimitSpec `json:"local,omitempty"`
}
// LocalRateLimitSpec defines the local rate limiting specification
// for the upstream host.
type LocalRateLimitSpec struct {
// TCP defines the local rate limiting specification at the network
// level. This is a token bucket rate limiter where each connection
// consumes a single token. If the token is available, the connection
// will be allowed. If no tokens are available, the connection will be
// immediately closed.
// +optional
TCP *TCPLocalRateLimitSpec `json:"tcp,omitempty"`
// HTTP defines the local rate limiting specification for HTTP traffic.
// This is a token bucket rate limiter where each request consumes
// a single token. If the token is available, the request will be
// allowed. If no tokens are available, the request will receive the
// configured rate limit status.
HTTP *HTTPLocalRateLimitSpec `json:"http,omitempty"`
}
// TCPLocalRateLimitSpec defines the local rate limiting specification
// for the upstream host at the TCP level.
type TCPLocalRateLimitSpec struct {
// Connections defines the number of connections allowed
// per unit of time before rate limiting occurs.
Connections uint32 `json:"connections"`
// Unit defines the period of time within which connections
// over the limit will be rate limited.
// Valid values are "second", "minute" and "hour".
Unit string `json:"unit"`
// Burst defines the number of connections above the baseline
// rate that are allowed in a short period of time.
// +optional
Burst uint32 `json:"burst,omitempty"`
}
// HTTPLocalRateLimitSpec defines the local rate limiting specification
// for the upstream host at the HTTP level.
type HTTPLocalRateLimitSpec struct {
// Requests defines the number of requests allowed
// per unit of time before rate limiting occurs.
Requests uint32 `json:"requests"`
// Unit defines the period of time within which requests
// over the limit will be rate limited.
// Valid values are "second", "minute" and "hour".
Unit string `json:"unit"`
// Burst defines the number of requests above the baseline
// rate that are allowed in a short period of time.
// +optional
Burst uint32 `json:"burst,omitempty"`
// ResponseStatusCode defines the HTTP status code to use for responses
// to rate limited requests. Code must be in the 400-599 (inclusive)
// error range. If not specified, a default of 429 (Too Many Requests) is used.
// See https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/v3/http_status.proto#enum-type-v3-statuscode
// for the list of HTTP status codes supported by Envoy.
// +optional
ResponseStatusCode uint32 `json:"responseStatusCode,omitempty"`
// ResponseHeadersToAdd defines the list of HTTP headers that should be
// added to each response for requests that have been rate limited.
// +optional
ResponseHeadersToAdd []HTTPHeaderValue `json:"responseHeadersToAdd,omitempty"`
}
// HTTPHeaderValue defines an HTTP header name/value pair
type HTTPHeaderValue struct {
// Name defines the name of the HTTP header.
Name string `json:"name"`
// Value defines the value of the header corresponding to the name key.
Value string `json:"value"`
}
// HTTPRouteSpec defines the settings correspondng to an HTTP route
type HTTPRouteSpec struct {
// Path defines the HTTP path.
Path string `json:"path"`
// RateLimit defines the HTTP rate limiting specification for
// the specified HTTP route.
RateLimit *HTTPPerRouteRateLimitSpec `json:"rateLimit,omitempty"`
}
// HTTPPerRouteRateLimitSpec defines the rate limiting specification
// per HTTP route.
type HTTPPerRouteRateLimitSpec struct {
// Local defines the local rate limiting specification
// applied per HTTP route.
Local *HTTPLocalRateLimitSpec `json:"local,omitempty"`
}
// UpstreamTrafficSettingStatus defines the status of an UpstreamTrafficSetting resource.
type UpstreamTrafficSettingStatus struct {
// CurrentStatus defines the current status of an UpstreamTrafficSetting resource.
// +optional
CurrentStatus string `json:"currentStatus,omitempty"`
// Reason defines the reason for the current status of an UpstreamTrafficSetting resource.
// +optional
Reason string `json:"reason,omitempty"`
}
// UpstreamTrafficSettingList defines the list of UpstreamTrafficSetting objects.
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type UpstreamTrafficSettingList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []UpstreamTrafficSetting `json:"items"`
}