-
Notifications
You must be signed in to change notification settings - Fork 88
/
backend_types.go
282 lines (231 loc) · 8.42 KB
/
backend_types.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// BackendProtocolType defines the backend protocol type.
type BackendProtocolType string
const (
// HTTPProtocol is the http protocol
HTTPProtocol BackendProtocolType = "http"
// HTTPSProtocol is the https protocol
HTTPSProtocol BackendProtocolType = "https"
// WSProtocol is the ws protocol
WSProtocol BackendProtocolType = "ws"
// WSSProtocol is the wss protocol
WSSProtocol BackendProtocolType = "wss"
)
// BackendSpec defines the desired state of Backend
type BackendSpec struct {
// Services holds hosts and ports
//
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=1
Services []Service `json:"services,omitempty"`
// Protocol defines the backend protocol
//
// +optional
// +kubebuilder:validation:Enum=http;https;ws;wss
// +kubebuilder:default=http
Protocol BackendProtocolType `json:"protocol"`
// BasePath defines the base path of the backend
// +optional
BasePath string `json:"basePath"`
// TLS defines the TLS configurations of the backend
TLS *TLSConfig `json:"tls,omitempty"`
// Security defines the security configurations of the backend
Security *SecurityConfig `json:"security,omitempty"`
// CircuitBreaker defines the circuit breaker configurations
CircuitBreaker *CircuitBreaker `json:"circuitBreaker,omitempty"`
// Timeout configuration for the backend
Timeout *Timeout `json:"timeout,omitempty"`
// Retry configuration for the backend
Retry *RetryConfig `json:"retry,omitempty"`
// HealthCheck configuration for the backend tcp health check
HealthCheck *HealthCheck `json:"healthCheck,omitempty"`
}
// HealthCheck defines the health check configurations
type HealthCheck struct {
// Timeout is the time to wait for a health check response.
// If the timeout is reached the health check attempt will be considered a failure.
//
// +kubebuilder:default=1
// +optional
Timeout uint32 `json:"timeout,omitempty"`
// Interval is the time between health check attempts in seconds.
//
// +kubebuilder:default=30
// +optional
Interval uint32 `json:"interval,omitempty"`
// UnhealthyThreshold is the number of consecutive health check failures required
// before a backend is marked unhealthy.
//
// +kubebuilder:default=2
// +optional
UnhealthyThreshold uint32 `json:"unhealthyThreshold,omitempty"`
// HealthyThreshold is the number of healthy health checks required before a host is marked healthy.
// Note that during startup, only a single successful health check is required to mark a host healthy.
//
// +kubebuilder:default=2
// +optional
HealthyThreshold uint32 `json:"healthyThreshold,omitempty"`
}
// Timeout defines the timeout configurations
type Timeout struct {
// UpstreamResponseTimeout spans between the point at which the entire downstream request (i.e. end-of-stream) has been processed and
// when the upstream response has been completely processed.
// A value of 0 will disable the route’s timeout.
//
// +kubebuilder:default=15
UpstreamResponseTimeout uint32 `json:"upstreamResponseTimeout"`
// DownstreamRequestIdleTimeout bounds the amount of time the request's stream may be idle.
// A value of 0 will completely disable the route's idle timeout.
//
// +kubebuilder:default=300
// +optional
DownstreamRequestIdleTimeout uint32 `json:"downstreamRequestIdleTimeout"`
}
// CircuitBreaker defines the circuit breaker configurations
type CircuitBreaker struct {
// MaxConnections is the maximum number of connections that will make to the upstream cluster.
//
// +kubebuilder:default=1024
// +optional
MaxConnections uint32 `json:"maxConnections"`
// MaxPendingRequests is the maximum number of pending requests that will allow to the upstream cluster.
//
// +kubebuilder:default=1024
// +optional
MaxPendingRequests uint32 `json:"maxPendingRequests"`
// MaxRequests is the maximum number of parallel requests that will make to the upstream cluster.
//
// +kubebuilder:default=1024
// +optional
MaxRequests uint32 `json:"maxRequests"`
// MaxRetries is the maximum number of parallel retries that will allow to the upstream cluster.
//
// +kubebuilder:default=3
// +optional
MaxRetries uint32 `json:"maxRetries"`
// MaxConnectionPools is the maximum number of parallel connection pools that will allow to the upstream cluster.
// If not specified, the default is unlimited.
//
// +optional
// +kubebuilder:validation:Minimum=1
MaxConnectionPools uint32 `json:"maxConnectionPools"`
}
// RetryConfig defines retry configurations
type RetryConfig struct {
// Count defines the number of retries.
// If exceeded, TooEarly(425 response code) response will be sent to the client.
//
// +kubebuilder:default=1
Count uint32 `json:"count"`
// BaseIntervalMillis is exponential retry back off and it defines the base interval between retries in milliseconds.
// maximum interval is 10 times of the BaseIntervalMillis
//
// +kubebuilder:default=25
// +kubebuilder:validation:Minimum=1
// +optional
BaseIntervalMillis uint32 `json:"baseIntervalMillis"`
// StatusCodes defines the list of status codes to retry
//
// +optional
StatusCodes []uint32 `json:"statusCodes,omitempty"`
}
// Service holds host and port information for the service
type Service struct {
// Host is the hostname of the service
//
// +kubebuilder:validation:MinLength=1
Host string `json:"host"`
// Port of the service
Port uint32 `json:"port"`
}
// TLSConfig defines enpoint TLS configurations
type TLSConfig struct {
// CertificateInline is the Inline Certificate entry
CertificateInline *string `json:"certificateInline,omitempty"`
// SecretRef denotes the reference to the Secret that contains the Certificate
SecretRef *RefConfig `json:"secretRef,omitempty"`
// ConfigMapRef denotes the reference to the ConfigMap that contains the Certificate
ConfigMapRef *RefConfig `json:"configMapRef,omitempty"`
// AllowedCNs is the list of allowed Subject Alternative Names (SANs)
//
// +optional
AllowedSANs []string `json:"allowedSANs,omitempty"`
}
// RefConfig holds a config for a secret or a configmap
type RefConfig struct {
// Name of the secret or configmap
//
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
// Key of the secret or configmap
//
// +kubebuilder:validation:MinLength=1
Key string `json:"key"`
}
// SecurityConfig defines enpoint security configurations
type SecurityConfig struct {
// Basic security configuration
Basic *BasicSecurityConfig `json:"basic,omitempty"`
}
// BasicSecurityConfig defines basic security configurations
type BasicSecurityConfig struct {
// SecretRef to credentials
SecretRef SecretRef `json:"secretRef"`
}
// SecretRef to credentials
type SecretRef struct {
// Name of the secret
//
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
// Namespace of the secret
//
// +kubebuilder:validation:MinLength=1
UsernameKey string `json:"usernameKey"`
// Key of the secret
//
// +kubebuilder:validation:MinLength=1
PasswordKey string `json:"passwordKey"`
}
// BackendStatus defines the observed state of Backend
type BackendStatus struct{}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// Backend is the Schema for the backends API
type Backend struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BackendSpec `json:"spec,omitempty"`
Status BackendStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// BackendList contains a list of Backend
type BackendList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backend `json:"items"`
}
func init() {
SchemeBuilder.Register(&Backend{}, &BackendList{})
}