-
Notifications
You must be signed in to change notification settings - Fork 361
/
healthcheck_types.go
205 lines (178 loc) · 8.25 KB
/
healthcheck_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
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.
package v1alpha1
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// HealthCheck configuration to decide which endpoints
// are healthy and can be used for routing.
type HealthCheck struct {
// Active health check configuration
// +optional
Active *ActiveHealthCheck `json:"active,omitempty"`
// Passive passive check configuration
// +optional
Passive *PassiveHealthCheck `json:"passive,omitempty"`
}
// PassiveHealthCheck defines the configuration for passive health checks in the context of Envoy's Outlier Detection,
// see https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/outlier
type PassiveHealthCheck struct {
// SplitExternalLocalOriginErrors enables splitting of errors between external and local origin.
//
// +kubebuilder:default=false
// +optional
SplitExternalLocalOriginErrors *bool `json:"splitExternalLocalOriginErrors,omitempty"`
// Interval defines the time between passive health checks.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="3s"
// +optional
Interval *metav1.Duration `json:"interval,omitempty"`
// ConsecutiveLocalOriginFailures sets the number of consecutive local origin failures triggering ejection.
// Parameter takes effect only when split_external_local_origin_errors is set to true.
//
// +kubebuilder:default=5
// +optional
ConsecutiveLocalOriginFailures *uint32 `json:"consecutiveLocalOriginFailures,omitempty"`
// ConsecutiveGatewayErrors sets the number of consecutive gateway errors triggering ejection.
//
// +kubebuilder:default=0
// +optional
ConsecutiveGatewayErrors *uint32 `json:"consecutiveGatewayErrors,omitempty"`
// Consecutive5xxErrors sets the number of consecutive 5xx errors triggering ejection.
//
// +kubebuilder:default=5
// +optional
Consecutive5xxErrors *uint32 `json:"consecutive5XxErrors,omitempty"`
// BaseEjectionTime defines the base duration for which a host will be ejected on consecutive failures.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="30s"
// +optional
BaseEjectionTime *metav1.Duration `json:"baseEjectionTime,omitempty"`
// MaxEjectionPercent sets the maximum percentage of hosts in a cluster that can be ejected.
//
// +kubebuilder:default=10
// +optional
MaxEjectionPercent *int32 `json:"maxEjectionPercent,omitempty"`
}
// ActiveHealthCheck defines the active health check configuration.
// EG supports various types of active health checking including HTTP, TCP.
// +union
//
// +kubebuilder:validation:XValidation:rule="self.type == 'HTTP' ? has(self.http) : !has(self.http)",message="If Health Checker type is HTTP, http field needs to be set."
// +kubebuilder:validation:XValidation:rule="self.type == 'TCP' ? has(self.tcp) : !has(self.tcp)",message="If Health Checker type is TCP, tcp field needs to be set."
// +kubebuilder:validation:XValidation:rule="has(self.grpc) ? self.type == 'GRPC' : true", message="The grpc field can only be set if the Health Checker type is GRPC."
type ActiveHealthCheck struct {
// Timeout defines the time to wait for a health check response.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="1s"
// +optional
Timeout *metav1.Duration `json:"timeout"`
// Interval defines the time between active health checks.
//
// +kubebuilder:validation:Format=duration
// +kubebuilder:default="3s"
// +optional
Interval *metav1.Duration `json:"interval"`
// UnhealthyThreshold defines the number of unhealthy health checks required before a backend host is marked unhealthy.
//
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=3
// +optional
UnhealthyThreshold *uint32 `json:"unhealthyThreshold"`
// HealthyThreshold defines the number of healthy health checks required before a backend host is marked healthy.
//
// +kubebuilder:validation:Minimum=1
// +kubebuilder:default=1
// +optional
HealthyThreshold *uint32 `json:"healthyThreshold"`
// Type defines the type of health checker.
// +kubebuilder:validation:Enum=HTTP;TCP;GRPC
// +unionDiscriminator
Type ActiveHealthCheckerType `json:"type" yaml:"type"`
// HTTP defines the configuration of http health checker.
// It's required while the health checker type is HTTP.
// +optional
HTTP *HTTPActiveHealthChecker `json:"http,omitempty" yaml:"http,omitempty"`
// TCP defines the configuration of tcp health checker.
// It's required while the health checker type is TCP.
// +optional
TCP *TCPActiveHealthChecker `json:"tcp,omitempty" yaml:"tcp,omitempty"`
// GRPC defines the configuration of the GRPC health checker.
// It's optional, and can only be used if the specified type is GRPC.
// +optional
GRPC *GRPCActiveHealthChecker `json:"grpc,omitempty" yaml:"grpc,omitempty"`
}
// ActiveHealthCheckerType is the type of health checker.
// +kubebuilder:validation:Enum=HTTP;TCP;GRPC
type ActiveHealthCheckerType string
const (
// ActiveHealthCheckerTypeHTTP defines the HTTP type of health checking.
ActiveHealthCheckerTypeHTTP ActiveHealthCheckerType = "HTTP"
// ActiveHealthCheckerTypeTCP defines the TCP type of health checking.
ActiveHealthCheckerTypeTCP ActiveHealthCheckerType = "TCP"
// ActiveHealthCheckerTypeGRPC defines the GRPC type of health checking.
ActiveHealthCheckerTypeGRPC ActiveHealthCheckerType = "GRPC"
)
// HTTPActiveHealthChecker defines the settings of http health check.
type HTTPActiveHealthChecker struct {
// Path defines the HTTP path that will be requested during health checking.
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=1024
Path string `json:"path" yaml:"path"`
// Method defines the HTTP method used for health checking.
// Defaults to GET
// +optional
Method *string `json:"method,omitempty" yaml:"method,omitempty"`
// ExpectedStatuses defines a list of HTTP response statuses considered healthy.
// Defaults to 200 only
// +optional
ExpectedStatuses []HTTPStatus `json:"expectedStatuses,omitempty" yaml:"expectedStatuses,omitempty"`
// ExpectedResponse defines a list of HTTP expected responses to match.
// +optional
ExpectedResponse *ActiveHealthCheckPayload `json:"expectedResponse,omitempty" yaml:"expectedResponse,omitempty"`
}
// TCPActiveHealthChecker defines the settings of tcp health check.
type TCPActiveHealthChecker struct {
// Send defines the request payload.
// +optional
Send *ActiveHealthCheckPayload `json:"send,omitempty" yaml:"send,omitempty"`
// Receive defines the expected response payload.
// +optional
Receive *ActiveHealthCheckPayload `json:"receive,omitempty" yaml:"receive,omitempty"`
}
// GRPCActiveHealthChecker defines the settings of the GRPC health check.
type GRPCActiveHealthChecker struct {
// Service to send in the health check request.
// If this is not specified, then the health check request applies to the entire
// server and not to a specific service.
// +optional
Service *string `json:"service,omitempty" yaml:"service,omitempty"`
}
// ActiveHealthCheckPayloadType is the type of the payload.
// +kubebuilder:validation:Enum=Text;Binary
type ActiveHealthCheckPayloadType string
const (
// ActiveHealthCheckPayloadTypeText defines the Text type payload.
ActiveHealthCheckPayloadTypeText ActiveHealthCheckPayloadType = "Text"
// ActiveHealthCheckPayloadTypeBinary defines the Binary type payload.
ActiveHealthCheckPayloadTypeBinary ActiveHealthCheckPayloadType = "Binary"
)
// ActiveHealthCheckPayload defines the encoding of the payload bytes in the payload.
// +union
// +kubebuilder:validation:XValidation:rule="self.type == 'Text' ? has(self.text) : !has(self.text)",message="If payload type is Text, text field needs to be set."
// +kubebuilder:validation:XValidation:rule="self.type == 'Binary' ? has(self.binary) : !has(self.binary)",message="If payload type is Binary, binary field needs to be set."
type ActiveHealthCheckPayload struct {
// Type defines the type of the payload.
// +kubebuilder:validation:Enum=Text;Binary
// +unionDiscriminator
Type ActiveHealthCheckPayloadType `json:"type" yaml:"type"`
// Text payload in plain text.
// +optional
Text *string `json:"text,omitempty" yaml:"text,omitempty"`
// Binary payload base64 encoded.
// +optional
Binary []byte `json:"binary,omitempty" yaml:"binary,omitempty"`
}