From fb8d48c7e5173f17bd8dc4a6494814ac5785bbe9 Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Wed, 31 Jan 2024 02:48:08 -0800 Subject: [PATCH] api: move healthCheck to healthCheck.active (#2540) * api: move healthCheck to healthCheck.active Fixes: https://github.com/envoyproxy/gateway/issues/2511 Signed-off-by: Arko Dasgupta * add charts Signed-off-by: Arko Dasgupta * fix cel Signed-off-by: Arko Dasgupta --------- Signed-off-by: Arko Dasgupta --- api/v1alpha1/healthcheck_types.go | 64 ++-- api/v1alpha1/zz_generated.deepcopy.go | 198 ++++++----- ....envoyproxy.io_backendtrafficpolicies.yaml | 321 +++++++++--------- internal/gatewayapi/backendtrafficpolicy.go | 28 +- ...kendtrafficpolicy-with-healthcheck.in.yaml | 108 +++--- ...endtrafficpolicy-with-healthcheck.out.yaml | 108 +++--- site/content/en/latest/api/extension_types.md | 150 ++++---- .../backendtrafficpolicy_test.go | 152 +++++---- 8 files changed, 605 insertions(+), 524 deletions(-) diff --git a/api/v1alpha1/healthcheck_types.go b/api/v1alpha1/healthcheck_types.go index a308c7d5719..05f70937b3c 100644 --- a/api/v1alpha1/healthcheck_types.go +++ b/api/v1alpha1/healthcheck_types.go @@ -7,13 +7,21 @@ package v1alpha1 import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -// HealthCheck defines the health check configuration. -// EG supports various types of health checking including HTTP, TCP. +// 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"` +} + +// 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." -type HealthCheck struct { +type ActiveHealthCheck struct { // Timeout defines the time to wait for a health check response. // // +kubebuilder:validation:Format=duration @@ -45,32 +53,32 @@ type HealthCheck struct { // Type defines the type of health checker. // +kubebuilder:validation:Enum=HTTP;TCP // +unionDiscriminator - Type HealthCheckerType `json:"type" yaml:"type"` + 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 *HTTPHealthChecker `json:"http,omitempty" yaml:"http,omitempty"` + 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 *TCPHealthChecker `json:"tcp,omitempty" yaml:"tcp,omitempty"` + TCP *TCPActiveHealthChecker `json:"tcp,omitempty" yaml:"tcp,omitempty"` } -// HealthCheckerType is the type of health checker. +// ActiveHealthCheckerType is the type of health checker. // +kubebuilder:validation:Enum=HTTP;TCP -type HealthCheckerType string +type ActiveHealthCheckerType string const ( - // HealthCheckerTypeHTTP defines the HTTP type of health checking. - HealthCheckerTypeHTTP HealthCheckerType = "HTTP" - // HealthCheckerTypeTCP defines the TCP type of health checking. - HealthCheckerTypeTCP HealthCheckerType = "TCP" + // ActiveHealthCheckerTypeHTTP defines the HTTP type of health checking. + ActiveHealthCheckerTypeHTTP ActiveHealthCheckerType = "HTTP" + // ActiveHealthCheckerTypeTCP defines the TCP type of health checking. + ActiveHealthCheckerTypeTCP ActiveHealthCheckerType = "TCP" ) -// HTTPHealthChecker defines the settings of http health check. -type HTTPHealthChecker struct { +// 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 @@ -85,17 +93,17 @@ type HTTPHealthChecker struct { ExpectedStatuses []HTTPStatus `json:"expectedStatuses,omitempty" yaml:"expectedStatuses,omitempty"` // ExpectedResponse defines a list of HTTP expected responses to match. // +optional - ExpectedResponse *HealthCheckPayload `json:"expectedResponse,omitempty" yaml:"expectedResponse,omitempty"` + ExpectedResponse *ActiveHealthCheckPayload `json:"expectedResponse,omitempty" yaml:"expectedResponse,omitempty"` } -// TCPHealthChecker defines the settings of tcp health check. -type TCPHealthChecker struct { +// TCPActiveHealthChecker defines the settings of tcp health check. +type TCPActiveHealthChecker struct { // Send defines the request payload. // +optional - Send *HealthCheckPayload `json:"send,omitempty" yaml:"send,omitempty"` + Send *ActiveHealthCheckPayload `json:"send,omitempty" yaml:"send,omitempty"` // Receive defines the expected response payload. // +optional - Receive *HealthCheckPayload `json:"receive,omitempty" yaml:"receive,omitempty"` + Receive *ActiveHealthCheckPayload `json:"receive,omitempty" yaml:"receive,omitempty"` } // HTTPStatus defines the http status code. @@ -104,26 +112,26 @@ type TCPHealthChecker struct { // +kubebuilder:validation:ExclusiveMaximum=true type HTTPStatus int -// HealthCheckPayloadType is the type of the payload. +// ActiveHealthCheckPayloadType is the type of the payload. // +kubebuilder:validation:Enum=Text;Binary -type HealthCheckPayloadType string +type ActiveHealthCheckPayloadType string const ( - // HealthCheckPayloadTypeText defines the Text type payload. - HealthCheckPayloadTypeText HealthCheckPayloadType = "Text" - // HealthCheckPayloadTypeBinary defines the Binary type payload. - HealthCheckPayloadTypeBinary HealthCheckPayloadType = "Binary" + // ActiveHealthCheckPayloadTypeText defines the Text type payload. + ActiveHealthCheckPayloadTypeText ActiveHealthCheckPayloadType = "Text" + // ActiveHealthCheckPayloadTypeBinary defines the Binary type payload. + ActiveHealthCheckPayloadTypeBinary ActiveHealthCheckPayloadType = "Binary" ) -// HealthCheckPayload defines the encoding of the payload bytes in the payload. +// 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 HealthCheckPayload struct { +type ActiveHealthCheckPayload struct { // Type defines the type of the payload. // +kubebuilder:validation:Enum=Text;Binary // +unionDiscriminator - Type HealthCheckPayloadType `json:"type" yaml:"type"` + Type ActiveHealthCheckPayloadType `json:"type" yaml:"type"` // Text payload in plain text. // +optional Text *string `json:"text,omitempty" yaml:"text,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 523f0aea7c3..c1d9b046d82 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -18,6 +18,76 @@ import ( apisv1 "sigs.k8s.io/gateway-api/apis/v1" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActiveHealthCheck) DeepCopyInto(out *ActiveHealthCheck) { + *out = *in + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(v1.Duration) + **out = **in + } + if in.Interval != nil { + in, out := &in.Interval, &out.Interval + *out = new(v1.Duration) + **out = **in + } + if in.UnhealthyThreshold != nil { + in, out := &in.UnhealthyThreshold, &out.UnhealthyThreshold + *out = new(uint32) + **out = **in + } + if in.HealthyThreshold != nil { + in, out := &in.HealthyThreshold, &out.HealthyThreshold + *out = new(uint32) + **out = **in + } + if in.HTTP != nil { + in, out := &in.HTTP, &out.HTTP + *out = new(HTTPActiveHealthChecker) + (*in).DeepCopyInto(*out) + } + if in.TCP != nil { + in, out := &in.TCP, &out.TCP + *out = new(TCPActiveHealthChecker) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActiveHealthCheck. +func (in *ActiveHealthCheck) DeepCopy() *ActiveHealthCheck { + if in == nil { + return nil + } + out := new(ActiveHealthCheck) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActiveHealthCheckPayload) DeepCopyInto(out *ActiveHealthCheckPayload) { + *out = *in + if in.Text != nil { + in, out := &in.Text, &out.Text + *out = new(string) + **out = **in + } + if in.Binary != nil { + in, out := &in.Binary, &out.Binary + *out = make([]byte, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActiveHealthCheckPayload. +func (in *ActiveHealthCheckPayload) DeepCopy() *ActiveHealthCheckPayload { + if in == nil { + return nil + } + out := new(ActiveHealthCheckPayload) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BackendTrafficPolicy) DeepCopyInto(out *BackendTrafficPolicy) { *out = *in @@ -1543,6 +1613,36 @@ func (in *HTTP3Settings) DeepCopy() *HTTP3Settings { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HTTPActiveHealthChecker) DeepCopyInto(out *HTTPActiveHealthChecker) { + *out = *in + if in.Method != nil { + in, out := &in.Method, &out.Method + *out = new(string) + **out = **in + } + if in.ExpectedStatuses != nil { + in, out := &in.ExpectedStatuses, &out.ExpectedStatuses + *out = make([]HTTPStatus, len(*in)) + copy(*out, *in) + } + if in.ExpectedResponse != nil { + in, out := &in.ExpectedResponse, &out.ExpectedResponse + *out = new(ActiveHealthCheckPayload) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPActiveHealthChecker. +func (in *HTTPActiveHealthChecker) DeepCopy() *HTTPActiveHealthChecker { + if in == nil { + return nil + } + out := new(HTTPActiveHealthChecker) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HTTPExtAuthService) DeepCopyInto(out *HTTPExtAuthService) { *out = *in @@ -1578,36 +1678,6 @@ func (in *HTTPExtAuthService) DeepCopy() *HTTPExtAuthService { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HTTPHealthChecker) DeepCopyInto(out *HTTPHealthChecker) { - *out = *in - if in.Method != nil { - in, out := &in.Method, &out.Method - *out = new(string) - **out = **in - } - if in.ExpectedStatuses != nil { - in, out := &in.ExpectedStatuses, &out.ExpectedStatuses - *out = make([]HTTPStatus, len(*in)) - copy(*out, *in) - } - if in.ExpectedResponse != nil { - in, out := &in.ExpectedResponse, &out.ExpectedResponse - *out = new(HealthCheckPayload) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPHealthChecker. -func (in *HTTPHealthChecker) DeepCopy() *HTTPHealthChecker { - if in == nil { - return nil - } - out := new(HTTPHealthChecker) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HTTPTimeout) DeepCopyInto(out *HTTPTimeout) { *out = *in @@ -1661,34 +1731,9 @@ func (in *HeaderMatch) DeepCopy() *HeaderMatch { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HealthCheck) DeepCopyInto(out *HealthCheck) { *out = *in - if in.Timeout != nil { - in, out := &in.Timeout, &out.Timeout - *out = new(v1.Duration) - **out = **in - } - if in.Interval != nil { - in, out := &in.Interval, &out.Interval - *out = new(v1.Duration) - **out = **in - } - if in.UnhealthyThreshold != nil { - in, out := &in.UnhealthyThreshold, &out.UnhealthyThreshold - *out = new(uint32) - **out = **in - } - if in.HealthyThreshold != nil { - in, out := &in.HealthyThreshold, &out.HealthyThreshold - *out = new(uint32) - **out = **in - } - if in.HTTP != nil { - in, out := &in.HTTP, &out.HTTP - *out = new(HTTPHealthChecker) - (*in).DeepCopyInto(*out) - } - if in.TCP != nil { - in, out := &in.TCP, &out.TCP - *out = new(TCPHealthChecker) + if in.Active != nil { + in, out := &in.Active, &out.Active + *out = new(ActiveHealthCheck) (*in).DeepCopyInto(*out) } } @@ -1703,31 +1748,6 @@ func (in *HealthCheck) DeepCopy() *HealthCheck { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HealthCheckPayload) DeepCopyInto(out *HealthCheckPayload) { - *out = *in - if in.Text != nil { - in, out := &in.Text, &out.Text - *out = new(string) - **out = **in - } - if in.Binary != nil { - in, out := &in.Binary, &out.Binary - *out = make([]byte, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HealthCheckPayload. -func (in *HealthCheckPayload) DeepCopy() *HealthCheckPayload { - if in == nil { - return nil - } - out := new(HealthCheckPayload) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JSONPatchOperation) DeepCopyInto(out *JSONPatchOperation) { *out = *in @@ -2987,26 +3007,26 @@ func (in *StringMatch) DeepCopy() *StringMatch { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TCPHealthChecker) DeepCopyInto(out *TCPHealthChecker) { +func (in *TCPActiveHealthChecker) DeepCopyInto(out *TCPActiveHealthChecker) { *out = *in if in.Send != nil { in, out := &in.Send, &out.Send - *out = new(HealthCheckPayload) + *out = new(ActiveHealthCheckPayload) (*in).DeepCopyInto(*out) } if in.Receive != nil { in, out := &in.Receive, &out.Receive - *out = new(HealthCheckPayload) + *out = new(ActiveHealthCheckPayload) (*in).DeepCopyInto(*out) } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TCPHealthChecker. -func (in *TCPHealthChecker) DeepCopy() *TCPHealthChecker { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TCPActiveHealthChecker. +func (in *TCPActiveHealthChecker) DeepCopy() *TCPActiveHealthChecker { if in == nil { return nil } - out := new(TCPHealthChecker) + out := new(TCPActiveHealthChecker) in.DeepCopyInto(out) return out } diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml index ba3152ef06b..d36b1fe290b 100644 --- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml +++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml @@ -162,173 +162,182 @@ spec: description: HealthCheck allows gateway to perform active health checking on backends. properties: - healthyThreshold: - default: 1 - description: HealthyThreshold defines the number of healthy health - checks required before a backend host is marked healthy. - format: int32 - minimum: 1 - type: integer - http: - description: HTTP defines the configuration of http health checker. - It's required while the health checker type is HTTP. + active: + description: Active health check configuration properties: - expectedResponse: - description: ExpectedResponse defines a list of HTTP expected - responses to match. + healthyThreshold: + default: 1 + description: HealthyThreshold defines the number of healthy + health checks required before a backend host is marked healthy. + format: int32 + minimum: 1 + type: integer + http: + description: HTTP defines the configuration of http health + checker. It's required while the health checker type is + HTTP. properties: - binary: - description: Binary payload base64 encoded. - format: byte - type: string - text: - description: Text payload in plain text. + expectedResponse: + description: ExpectedResponse defines a list of HTTP expected + responses to match. + properties: + binary: + description: Binary payload base64 encoded. + format: byte + type: string + text: + description: Text payload in plain text. + type: string + type: + allOf: + - enum: + - Text + - Binary + - enum: + - Text + - Binary + description: Type defines the type of the payload. + type: string + required: + - type + type: object + x-kubernetes-validations: + - message: If payload type is Text, text field needs to + be set. + rule: 'self.type == ''Text'' ? has(self.text) : !has(self.text)' + - message: If payload type is Binary, binary field needs + to be set. + rule: 'self.type == ''Binary'' ? has(self.binary) : + !has(self.binary)' + expectedStatuses: + description: ExpectedStatuses defines a list of HTTP response + statuses considered healthy. Defaults to 200 only + items: + description: HTTPStatus defines the http status code. + exclusiveMaximum: true + maximum: 600 + minimum: 100 + type: integer + type: array + method: + description: Method defines the HTTP method used for health + checking. Defaults to GET type: string - type: - allOf: - - enum: - - Text - - Binary - - enum: - - Text - - Binary - description: Type defines the type of the payload. + path: + description: Path defines the HTTP path that will be requested + during health checking. + maxLength: 1024 + minLength: 1 type: string required: - - type + - path type: object - x-kubernetes-validations: - - message: If payload type is Text, text field needs to be - set. - rule: 'self.type == ''Text'' ? has(self.text) : !has(self.text)' - - message: If payload type is Binary, binary field needs to - be set. - rule: 'self.type == ''Binary'' ? has(self.binary) : !has(self.binary)' - expectedStatuses: - description: ExpectedStatuses defines a list of HTTP response - statuses considered healthy. Defaults to 200 only - items: - description: HTTPStatus defines the http status code. - exclusiveMaximum: true - maximum: 600 - minimum: 100 - type: integer - type: array - method: - description: Method defines the HTTP method used for health - checking. Defaults to GET - type: string - path: - description: Path defines the HTTP path that will be requested - during health checking. - maxLength: 1024 - minLength: 1 + interval: + default: 3s + description: Interval defines the time between health checks. + format: duration type: string - required: - - path - type: object - interval: - default: 3s - description: Interval defines the time between health checks. - format: duration - type: string - tcp: - description: TCP defines the configuration of tcp health checker. - It's required while the health checker type is TCP. - properties: - receive: - description: Receive defines the expected response payload. + tcp: + description: TCP defines the configuration of tcp health checker. + It's required while the health checker type is TCP. properties: - binary: - description: Binary payload base64 encoded. - format: byte - type: string - text: - description: Text payload in plain text. - type: string - type: - allOf: - - enum: - - Text - - Binary - - enum: - - Text - - Binary - description: Type defines the type of the payload. - type: string - required: - - type + receive: + description: Receive defines the expected response payload. + properties: + binary: + description: Binary payload base64 encoded. + format: byte + type: string + text: + description: Text payload in plain text. + type: string + type: + allOf: + - enum: + - Text + - Binary + - enum: + - Text + - Binary + description: Type defines the type of the payload. + type: string + required: + - type + type: object + x-kubernetes-validations: + - message: If payload type is Text, text field needs to + be set. + rule: 'self.type == ''Text'' ? has(self.text) : !has(self.text)' + - message: If payload type is Binary, binary field needs + to be set. + rule: 'self.type == ''Binary'' ? has(self.binary) : + !has(self.binary)' + send: + description: Send defines the request payload. + properties: + binary: + description: Binary payload base64 encoded. + format: byte + type: string + text: + description: Text payload in plain text. + type: string + type: + allOf: + - enum: + - Text + - Binary + - enum: + - Text + - Binary + description: Type defines the type of the payload. + type: string + required: + - type + type: object + x-kubernetes-validations: + - message: If payload type is Text, text field needs to + be set. + rule: 'self.type == ''Text'' ? has(self.text) : !has(self.text)' + - message: If payload type is Binary, binary field needs + to be set. + rule: 'self.type == ''Binary'' ? has(self.binary) : + !has(self.binary)' type: object - x-kubernetes-validations: - - message: If payload type is Text, text field needs to be - set. - rule: 'self.type == ''Text'' ? has(self.text) : !has(self.text)' - - message: If payload type is Binary, binary field needs to - be set. - rule: 'self.type == ''Binary'' ? has(self.binary) : !has(self.binary)' - send: - description: Send defines the request payload. - properties: - binary: - description: Binary payload base64 encoded. - format: byte - type: string - text: - description: Text payload in plain text. - type: string - type: - allOf: - - enum: - - Text - - Binary - - enum: - - Text - - Binary - description: Type defines the type of the payload. - type: string - required: - - type - type: object - x-kubernetes-validations: - - message: If payload type is Text, text field needs to be - set. - rule: 'self.type == ''Text'' ? has(self.text) : !has(self.text)' - - message: If payload type is Binary, binary field needs to - be set. - rule: 'self.type == ''Binary'' ? has(self.binary) : !has(self.binary)' + timeout: + default: 1s + description: Timeout defines the time to wait for a health + check response. + format: duration + type: string + type: + allOf: + - enum: + - HTTP + - TCP + - enum: + - HTTP + - TCP + description: Type defines the type of health checker. + type: string + unhealthyThreshold: + default: 3 + description: UnhealthyThreshold defines the number of unhealthy + health checks required before a backend host is marked unhealthy. + format: int32 + minimum: 1 + type: integer + required: + - type type: object - timeout: - default: 1s - description: Timeout defines the time to wait for a health check - response. - format: duration - type: string - type: - allOf: - - enum: - - HTTP - - TCP - - enum: - - HTTP - - TCP - description: Type defines the type of health checker. - type: string - unhealthyThreshold: - default: 3 - description: UnhealthyThreshold defines the number of unhealthy - health checks required before a backend host is marked unhealthy. - format: int32 - minimum: 1 - type: integer - required: - - type + x-kubernetes-validations: + - message: If Health Checker type is HTTP, http field needs to + be set. + rule: 'self.type == ''HTTP'' ? has(self.http) : !has(self.http)' + - message: If Health Checker type is TCP, tcp field needs to be + set. + rule: 'self.type == ''TCP'' ? has(self.tcp) : !has(self.tcp)' type: object - x-kubernetes-validations: - - message: If Health Checker type is HTTP, http field needs to be - set. - rule: 'self.type == ''HTTP'' ? has(self.http) : !has(self.http)' - - message: If Health Checker type is TCP, tcp field needs to be set. - rule: 'self.type == ''TCP'' ? has(self.tcp) : !has(self.tcp)' loadBalancer: description: LoadBalancer policy to apply when routing traffic from the gateway to the backend endpoints diff --git a/internal/gatewayapi/backendtrafficpolicy.go b/internal/gatewayapi/backendtrafficpolicy.go index 9d64daf63f2..90dab414d82 100644 --- a/internal/gatewayapi/backendtrafficpolicy.go +++ b/internal/gatewayapi/backendtrafficpolicy.go @@ -687,11 +687,11 @@ func (t *Translator) buildProxyProtocol(policy *egv1a1.BackendTrafficPolicy) *ir } func (t *Translator) buildHealthCheck(policy *egv1a1.BackendTrafficPolicy) *ir.HealthCheck { - if policy.Spec.HealthCheck == nil { + if policy.Spec.HealthCheck == nil || policy.Spec.HealthCheck.Active == nil { return nil } - hc := policy.Spec.HealthCheck + hc := policy.Spec.HealthCheck.Active irHC := &ir.HealthCheck{ Timeout: hc.Timeout, Interval: hc.Interval, @@ -699,16 +699,16 @@ func (t *Translator) buildHealthCheck(policy *egv1a1.BackendTrafficPolicy) *ir.H HealthyThreshold: hc.HealthyThreshold, } switch hc.Type { - case egv1a1.HealthCheckerTypeHTTP: - irHC.HTTP = t.buildHTTPHealthChecker(hc.HTTP) - case egv1a1.HealthCheckerTypeTCP: - irHC.TCP = t.buildTCPHealthChecker(hc.TCP) + case egv1a1.ActiveHealthCheckerTypeHTTP: + irHC.HTTP = t.buildHTTPActiveHealthChecker(hc.HTTP) + case egv1a1.ActiveHealthCheckerTypeTCP: + irHC.TCP = t.buildTCPActiveHealthChecker(hc.TCP) } return irHC } -func (t *Translator) buildHTTPHealthChecker(h *egv1a1.HTTPHealthChecker) *ir.HTTPHealthChecker { +func (t *Translator) buildHTTPActiveHealthChecker(h *egv1a1.HTTPActiveHealthChecker) *ir.HTTPHealthChecker { if h == nil { return nil } @@ -732,32 +732,32 @@ func (t *Translator) buildHTTPHealthChecker(h *egv1a1.HTTPHealthChecker) *ir.HTT } irHTTP.ExpectedStatuses = irStatuses - irHTTP.ExpectedResponse = translateHealthCheckPayload(h.ExpectedResponse) + irHTTP.ExpectedResponse = translateActiveHealthCheckPayload(h.ExpectedResponse) return irHTTP } -func (t *Translator) buildTCPHealthChecker(h *egv1a1.TCPHealthChecker) *ir.TCPHealthChecker { +func (t *Translator) buildTCPActiveHealthChecker(h *egv1a1.TCPActiveHealthChecker) *ir.TCPHealthChecker { if h == nil { return nil } irTCP := &ir.TCPHealthChecker{ - Send: translateHealthCheckPayload(h.Send), - Receive: translateHealthCheckPayload(h.Receive), + Send: translateActiveHealthCheckPayload(h.Send), + Receive: translateActiveHealthCheckPayload(h.Receive), } return irTCP } -func translateHealthCheckPayload(p *egv1a1.HealthCheckPayload) *ir.HealthCheckPayload { +func translateActiveHealthCheckPayload(p *egv1a1.ActiveHealthCheckPayload) *ir.HealthCheckPayload { if p == nil { return nil } irPayload := &ir.HealthCheckPayload{} switch p.Type { - case egv1a1.HealthCheckPayloadTypeText: + case egv1a1.ActiveHealthCheckPayloadTypeText: irPayload.Text = p.Text - case egv1a1.HealthCheckPayloadTypeBinary: + case egv1a1.ActiveHealthCheckPayloadTypeBinary: irPayload.Binary = make([]byte, len(p.Binary)) copy(irPayload.Binary, p.Binary) } diff --git a/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.in.yaml b/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.in.yaml index 31a494a527d..486f9c5abcb 100644 --- a/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.in.yaml +++ b/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.in.yaml @@ -113,20 +113,21 @@ backendTrafficPolicies: name: gateway-1 namespace: envoy-gateway healthCheck: - timeout: "500ms" - interval: "3s" - unhealthyThreshold: 3 - healthyThreshold: 1 - type: HTTP - http: - path: "/healthz" - method: "GET" - expectedStatuses: - - 200 - - 300 - expectedResponse: - type: Binary - binary: RXZlcnl0aGluZyBPSw== + active: + timeout: "500ms" + interval: "3s" + unhealthyThreshold: 3 + healthyThreshold: 1 + type: HTTP + http: + path: "/healthz" + method: "GET" + expectedStatuses: + - 200 + - 300 + expectedResponse: + type: Binary + binary: RXZlcnl0aGluZyBPSw== - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: BackendTrafficPolicy metadata: @@ -139,20 +140,21 @@ backendTrafficPolicies: name: httproute-1 namespace: default healthCheck: - timeout: "1s" - interval: "5s" - unhealthyThreshold: 3 - healthyThreshold: 3 - type: HTTP - http: - path: "/healthz" - method: "GET" - expectedStatuses: - - 200 - - 201 - expectedResponse: - type: Text - text: pong + active: + timeout: "1s" + interval: "5s" + unhealthyThreshold: 3 + healthyThreshold: 3 + type: HTTP + http: + path: "/healthz" + method: "GET" + expectedStatuses: + - 200 + - 201 + expectedResponse: + type: Text + text: pong - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: BackendTrafficPolicy metadata: @@ -165,18 +167,19 @@ backendTrafficPolicies: name: httproute-2 namespace: default healthCheck: - timeout: "1s" - interval: "5s" - unhealthyThreshold: 3 - healthyThreshold: 3 - type: TCP - tcp: - send: - type: Text - text: ping - receive: - type: Text - text: pong + active: + timeout: "1s" + interval: "5s" + unhealthyThreshold: 3 + healthyThreshold: 3 + type: TCP + tcp: + send: + type: Text + text: ping + receive: + type: Text + text: pong - apiVersion: gateway.envoyproxy.io/v1alpha1 kind: BackendTrafficPolicy metadata: @@ -189,15 +192,16 @@ backendTrafficPolicies: name: httproute-3 namespace: default healthCheck: - timeout: 1s - interval: 3s - unhealthyThreshold: 3 - healthyThreshold: 1 - type: TCP - tcp: - send: - type: Binary - binary: cGluZw== - receive: - type: Binary - binary: RXZlcnl0aGluZyBPSw== + active: + timeout: 1s + interval: 3s + unhealthyThreshold: 3 + healthyThreshold: 1 + type: TCP + tcp: + send: + type: Binary + binary: cGluZw== + receive: + type: Binary + binary: RXZlcnl0aGluZyBPSw== diff --git a/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.out.yaml b/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.out.yaml index 361a5298381..4a48cda66a5 100755 --- a/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.out.yaml +++ b/internal/gatewayapi/testdata/backendtrafficpolicy-with-healthcheck.out.yaml @@ -7,20 +7,21 @@ backendTrafficPolicies: namespace: default spec: healthCheck: - healthyThreshold: 3 - http: - expectedResponse: - text: pong - type: Text - expectedStatuses: - - 200 - - 201 - method: GET - path: /healthz - interval: 5s - timeout: 1s - type: HTTP - unhealthyThreshold: 3 + active: + healthyThreshold: 3 + http: + expectedResponse: + text: pong + type: Text + expectedStatuses: + - 200 + - 201 + method: GET + path: /healthz + interval: 5s + timeout: 1s + type: HTTP + unhealthyThreshold: 3 targetRef: group: gateway.networking.k8s.io kind: HTTPRoute @@ -41,18 +42,19 @@ backendTrafficPolicies: namespace: default spec: healthCheck: - healthyThreshold: 3 - interval: 5s - tcp: - receive: - text: pong - type: Text - send: - text: ping - type: Text - timeout: 1s - type: TCP - unhealthyThreshold: 3 + active: + healthyThreshold: 3 + interval: 5s + tcp: + receive: + text: pong + type: Text + send: + text: ping + type: Text + timeout: 1s + type: TCP + unhealthyThreshold: 3 targetRef: group: gateway.networking.k8s.io kind: HTTPRoute @@ -73,18 +75,19 @@ backendTrafficPolicies: namespace: default spec: healthCheck: - healthyThreshold: 1 - interval: 3s - tcp: - receive: - binary: RXZlcnl0aGluZyBPSw== - type: Binary - send: - binary: cGluZw== - type: Binary - timeout: 1s - type: TCP - unhealthyThreshold: 3 + active: + healthyThreshold: 1 + interval: 3s + tcp: + receive: + binary: RXZlcnl0aGluZyBPSw== + type: Binary + send: + binary: cGluZw== + type: Binary + timeout: 1s + type: TCP + unhealthyThreshold: 3 targetRef: group: gateway.networking.k8s.io kind: HTTPRoute @@ -105,20 +108,21 @@ backendTrafficPolicies: namespace: envoy-gateway spec: healthCheck: - healthyThreshold: 1 - http: - expectedResponse: - binary: RXZlcnl0aGluZyBPSw== - type: Binary - expectedStatuses: - - 200 - - 300 - method: GET - path: /healthz - interval: 3s - timeout: 500ms - type: HTTP - unhealthyThreshold: 3 + active: + healthyThreshold: 1 + http: + expectedResponse: + binary: RXZlcnl0aGluZyBPSw== + type: Binary + expectedStatuses: + - 200 + - 300 + method: GET + path: /healthz + interval: 3s + timeout: 500ms + type: HTTP + unhealthyThreshold: 3 targetRef: group: gateway.networking.k8s.io kind: Gateway diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md index 0c441fe12d3..ed705598c50 100644 --- a/site/content/en/latest/api/extension_types.md +++ b/site/content/en/latest/api/extension_types.md @@ -38,6 +38,65 @@ _Appears in:_ +#### ActiveHealthCheck + + + +ActiveHealthCheck defines the active health check configuration. EG supports various types of active health checking including HTTP, TCP. + +_Appears in:_ +- [HealthCheck](#healthcheck) + +| Field | Description | +| --- | --- | +| `timeout` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#duration-v1-meta)_ | Timeout defines the time to wait for a health check response. | +| `interval` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#duration-v1-meta)_ | Interval defines the time between health checks. | +| `unhealthyThreshold` _integer_ | UnhealthyThreshold defines the number of unhealthy health checks required before a backend host is marked unhealthy. | +| `healthyThreshold` _integer_ | HealthyThreshold defines the number of healthy health checks required before a backend host is marked healthy. | +| `type` _[ActiveHealthCheckerType](#activehealthcheckertype)_ | Type defines the type of health checker. | +| `http` _[HTTPActiveHealthChecker](#httpactivehealthchecker)_ | HTTP defines the configuration of http health checker. It's required while the health checker type is HTTP. | +| `tcp` _[TCPActiveHealthChecker](#tcpactivehealthchecker)_ | TCP defines the configuration of tcp health checker. It's required while the health checker type is TCP. | + + +#### ActiveHealthCheckPayload + + + +ActiveHealthCheckPayload defines the encoding of the payload bytes in the payload. + +_Appears in:_ +- [HTTPActiveHealthChecker](#httpactivehealthchecker) +- [TCPActiveHealthChecker](#tcpactivehealthchecker) + +| Field | Description | +| --- | --- | +| `type` _[ActiveHealthCheckPayloadType](#activehealthcheckpayloadtype)_ | Type defines the type of the payload. | +| `text` _string_ | Text payload in plain text. | +| `binary` _integer array_ | Binary payload base64 encoded. | + + +#### ActiveHealthCheckPayloadType + +_Underlying type:_ `string` + +ActiveHealthCheckPayloadType is the type of the payload. + +_Appears in:_ +- [ActiveHealthCheckPayload](#activehealthcheckpayload) + + + +#### ActiveHealthCheckerType + +_Underlying type:_ `string` + +ActiveHealthCheckerType is the type of health checker. + +_Appears in:_ +- [ActiveHealthCheck](#activehealthcheck) + + + #### BackendTrafficPolicy @@ -1031,39 +1090,39 @@ _Appears in:_ -#### HTTPExtAuthService +#### HTTPActiveHealthChecker -HTTPExtAuthService defines the HTTP External Authorization service +HTTPActiveHealthChecker defines the settings of http health check. _Appears in:_ -- [ExtAuth](#extauth) +- [ActiveHealthCheck](#activehealthcheck) | Field | Description | | --- | --- | -| `host` _PreciseHostname_ | Host is the hostname of the HTTP External Authorization service. | -| `port` _PortNumber_ | Port is the network port of the HTTP External Authorization service. If port is not specified, 80 for http and 443 for https are assumed. | -| `path` _string_ | Path is the path of the HTTP External Authorization service. If path is specified, the authorization request will be sent to that path, or else the authorization request will be sent to the root path. | -| `tls` _[TLSConfig](#tlsconfig)_ | TLS defines the TLS configuration for the HTTP External Authorization service. Note: If not specified, the proxy will talk to the HTTP External Authorization service in plaintext. | -| `headersToBackend` _string array_ | HeadersToBackend are the authorization response headers that will be added to the original client request before sending it to the backend server. Note that coexisting headers will be overridden. If not specified, no authorization response headers will be added to the original client request. | +| `path` _string_ | Path defines the HTTP path that will be requested during health checking. | +| `method` _string_ | Method defines the HTTP method used for health checking. Defaults to GET | +| `expectedStatuses` _[HTTPStatus](#httpstatus) array_ | ExpectedStatuses defines a list of HTTP response statuses considered healthy. Defaults to 200 only | +| `expectedResponse` _[ActiveHealthCheckPayload](#activehealthcheckpayload)_ | ExpectedResponse defines a list of HTTP expected responses to match. | -#### HTTPHealthChecker +#### HTTPExtAuthService -HTTPHealthChecker defines the settings of http health check. +HTTPExtAuthService defines the HTTP External Authorization service _Appears in:_ -- [HealthCheck](#healthcheck) +- [ExtAuth](#extauth) | Field | Description | | --- | --- | -| `path` _string_ | Path defines the HTTP path that will be requested during health checking. | -| `method` _string_ | Method defines the HTTP method used for health checking. Defaults to GET | -| `expectedStatuses` _[HTTPStatus](#httpstatus) array_ | ExpectedStatuses defines a list of HTTP response statuses considered healthy. Defaults to 200 only | -| `expectedResponse` _[HealthCheckPayload](#healthcheckpayload)_ | ExpectedResponse defines a list of HTTP expected responses to match. | +| `host` _PreciseHostname_ | Host is the hostname of the HTTP External Authorization service. | +| `port` _PortNumber_ | Port is the network port of the HTTP External Authorization service. If port is not specified, 80 for http and 443 for https are assumed. | +| `path` _string_ | Path is the path of the HTTP External Authorization service. If path is specified, the authorization request will be sent to that path, or else the authorization request will be sent to the root path. | +| `tls` _[TLSConfig](#tlsconfig)_ | TLS defines the TLS configuration for the HTTP External Authorization service. Note: If not specified, the proxy will talk to the HTTP External Authorization service in plaintext. | +| `headersToBackend` _string array_ | HeadersToBackend are the authorization response headers that will be added to the original client request before sending it to the backend server. Note that coexisting headers will be overridden. If not specified, no authorization response headers will be added to the original client request. | #### HTTPStatus @@ -1073,7 +1132,7 @@ _Underlying type:_ `integer` HTTPStatus defines the http status code. _Appears in:_ -- [HTTPHealthChecker](#httphealthchecker) +- [HTTPActiveHealthChecker](#httpactivehealthchecker) @@ -1107,59 +1166,14 @@ _Appears in:_ -HealthCheck defines the health check configuration. EG supports various types of health checking including HTTP, TCP. +HealthCheck configuration to decide which endpoints are healthy and can be used for routing. _Appears in:_ - [BackendTrafficPolicySpec](#backendtrafficpolicyspec) | Field | Description | | --- | --- | -| `timeout` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#duration-v1-meta)_ | Timeout defines the time to wait for a health check response. | -| `interval` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#duration-v1-meta)_ | Interval defines the time between health checks. | -| `unhealthyThreshold` _integer_ | UnhealthyThreshold defines the number of unhealthy health checks required before a backend host is marked unhealthy. | -| `healthyThreshold` _integer_ | HealthyThreshold defines the number of healthy health checks required before a backend host is marked healthy. | -| `type` _[HealthCheckerType](#healthcheckertype)_ | Type defines the type of health checker. | -| `http` _[HTTPHealthChecker](#httphealthchecker)_ | HTTP defines the configuration of http health checker. It's required while the health checker type is HTTP. | -| `tcp` _[TCPHealthChecker](#tcphealthchecker)_ | TCP defines the configuration of tcp health checker. It's required while the health checker type is TCP. | - - -#### HealthCheckPayload - - - -HealthCheckPayload defines the encoding of the payload bytes in the payload. - -_Appears in:_ -- [HTTPHealthChecker](#httphealthchecker) -- [TCPHealthChecker](#tcphealthchecker) - -| Field | Description | -| --- | --- | -| `type` _[HealthCheckPayloadType](#healthcheckpayloadtype)_ | Type defines the type of the payload. | -| `text` _string_ | Text payload in plain text. | -| `binary` _integer array_ | Binary payload base64 encoded. | - - -#### HealthCheckPayloadType - -_Underlying type:_ `string` - -HealthCheckPayloadType is the type of the payload. - -_Appears in:_ -- [HealthCheckPayload](#healthcheckpayload) - - - -#### HealthCheckerType - -_Underlying type:_ `string` - -HealthCheckerType is the type of health checker. - -_Appears in:_ -- [HealthCheck](#healthcheck) - +| `active` _[ActiveHealthCheck](#activehealthcheck)_ | Active health check configuration | #### InfrastructureProviderType @@ -2135,19 +2149,19 @@ _Appears in:_ -#### TCPHealthChecker +#### TCPActiveHealthChecker -TCPHealthChecker defines the settings of tcp health check. +TCPActiveHealthChecker defines the settings of tcp health check. _Appears in:_ -- [HealthCheck](#healthcheck) +- [ActiveHealthCheck](#activehealthcheck) | Field | Description | | --- | --- | -| `send` _[HealthCheckPayload](#healthcheckpayload)_ | Send defines the request payload. | -| `receive` _[HealthCheckPayload](#healthcheckpayload)_ | Receive defines the expected response payload. | +| `send` _[ActiveHealthCheckPayload](#activehealthcheckpayload)_ | Send defines the request payload. | +| `receive` _[ActiveHealthCheckPayload](#activehealthcheckpayload)_ | Receive defines the expected response payload. | #### TCPKeepalive diff --git a/test/cel-validation/backendtrafficpolicy_test.go b/test/cel-validation/backendtrafficpolicy_test.go index 24000f51867..947b88b970c 100644 --- a/test/cel-validation/backendtrafficpolicy_test.go +++ b/test/cel-validation/backendtrafficpolicy_test.go @@ -495,15 +495,17 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "", + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "", + }, }, }, } }, wantErrors: []string{ - `spec.healthCheck.http.path: Invalid value: "": spec.healthCheck.http.path in body should be at least 1 chars long`, + `spec.HealthCheck.active.http.path: Invalid value: "": spec.HealthCheck.active.http.path in body should be at least 1 chars long`, }, }, { @@ -518,16 +520,18 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - UnhealthyThreshold: ptr.To[uint32](0), - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", + Active: &egv1a1.ActiveHealthCheck{ + UnhealthyThreshold: ptr.To[uint32](0), + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + }, }, }, } }, wantErrors: []string{ - `spec.healthCheck.unhealthyThreshold: Invalid value: 0: spec.healthCheck.unhealthyThreshold in body should be greater than or equal to 1`, + `spec.HealthCheck.active.unhealthyThreshold: Invalid value: 0: spec.HealthCheck.active.unhealthyThreshold in body should be greater than or equal to 1`, }, }, { @@ -542,16 +546,18 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - HealthyThreshold: ptr.To[uint32](0), - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", + Active: &egv1a1.ActiveHealthCheck{ + HealthyThreshold: ptr.To[uint32](0), + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + }, }, }, } }, wantErrors: []string{ - `spec.healthCheck.healthyThreshold: Invalid value: 0: spec.healthCheck.healthyThreshold in body should be greater than or equal to 1`, + `spec.HealthCheck.active.healthyThreshold: Invalid value: 0: spec.HealthCheck.active.healthyThreshold in body should be greater than or equal to 1`, }, }, { @@ -566,13 +572,15 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - TCP: &egv1a1.TCPHealthChecker{}, + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + TCP: &egv1a1.TCPActiveHealthChecker{}, + }, }, } }, wantErrors: []string{ - `spec.healthCheck: Invalid value: "object": If Health Checker type is HTTP, http field needs to be set., spec.healthCheck: Invalid value: "object": If Health Checker type is TCP, tcp field needs to be set`, + `spec.HealthCheck.active: Invalid value: "object": If Health Checker type is HTTP, http field needs to be set., spec.HealthCheck.active: Invalid value: "object": If Health Checker type is TCP, tcp field needs to be set`, }, }, { @@ -587,16 +595,18 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", - ExpectedStatuses: []egv1a1.HTTPStatus{99, 200}, + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + ExpectedStatuses: []egv1a1.HTTPStatus{99, 200}, + }, }, }, } }, wantErrors: []string{ - `spec.healthCheck.http.expectedStatuses[0]: Invalid value: 99: spec.healthCheck.http.expectedStatuses[0] in body should be greater than or equal to 100`, + `spec.HealthCheck.active.http.expectedStatuses[0]: Invalid value: 99: spec.HealthCheck.active.http.expectedStatuses[0] in body should be greater than or equal to 100`, }, }, { @@ -611,10 +621,12 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", - ExpectedStatuses: []egv1a1.HTTPStatus{100, 200, 201}, + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + ExpectedStatuses: []egv1a1.HTTPStatus{100, 200, 201}, + }, }, }, } @@ -633,16 +645,18 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", - ExpectedStatuses: []egv1a1.HTTPStatus{200, 300, 601}, + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + ExpectedStatuses: []egv1a1.HTTPStatus{200, 300, 601}, + }, }, }, } }, wantErrors: []string{ - `spec.healthCheck.http.expectedStatuses[2]: Invalid value: 601: spec.healthCheck.http.expectedStatuses[2] in body should be less than 600`, + `spec.HealthCheck.active.http.expectedStatuses[2]: Invalid value: 601: spec.HealthCheck.active.http.expectedStatuses[2] in body should be less than 600`, }, }, { @@ -657,19 +671,21 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", - ExpectedResponse: &egv1a1.HealthCheckPayload{ - Type: egv1a1.HealthCheckPayloadTypeText, - Binary: []byte{'f', 'o', 'o'}, + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + ExpectedResponse: &egv1a1.ActiveHealthCheckPayload{ + Type: egv1a1.ActiveHealthCheckPayloadTypeText, + Binary: []byte{'f', 'o', 'o'}, + }, }, }, }, } }, wantErrors: []string{ - `[spec.healthCheck.http.expectedResponse: Invalid value: "object": If payload type is Text, text field needs to be set., spec.healthCheck.http.expectedResponse: Invalid value: "object": If payload type is Binary, binary field needs to be set.]`, + `[spec.HealthCheck.active.http.expectedResponse: Invalid value: "object": If payload type is Text, text field needs to be set., spec.HealthCheck.active.http.expectedResponse: Invalid value: "object": If payload type is Binary, binary field needs to be set.]`, }, }, { @@ -684,19 +700,21 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeHTTP, - HTTP: &egv1a1.HTTPHealthChecker{ - Path: "/healthz", - ExpectedResponse: &egv1a1.HealthCheckPayload{ - Type: egv1a1.HealthCheckPayloadTypeBinary, - Text: ptr.To("foo"), + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeHTTP, + HTTP: &egv1a1.HTTPActiveHealthChecker{ + Path: "/healthz", + ExpectedResponse: &egv1a1.ActiveHealthCheckPayload{ + Type: egv1a1.ActiveHealthCheckPayloadTypeBinary, + Text: ptr.To("foo"), + }, }, }, }, } }, wantErrors: []string{ - `[spec.healthCheck.http.expectedResponse: Invalid value: "object": If payload type is Text, text field needs to be set., spec.healthCheck.http.expectedResponse: Invalid value: "object": If payload type is Binary, binary field needs to be set.]`, + `[spec.HealthCheck.active.http.expectedResponse: Invalid value: "object": If payload type is Text, text field needs to be set., spec.HealthCheck.active.http.expectedResponse: Invalid value: "object": If payload type is Binary, binary field needs to be set.]`, }, }, { @@ -711,22 +729,24 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeTCP, - TCP: &egv1a1.TCPHealthChecker{ - Send: &egv1a1.HealthCheckPayload{ - Type: egv1a1.HealthCheckPayloadTypeText, - Binary: []byte{'f', 'o', 'o'}, - }, - Receive: &egv1a1.HealthCheckPayload{ - Type: egv1a1.HealthCheckPayloadTypeText, - Text: ptr.To("foo"), + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeTCP, + TCP: &egv1a1.TCPActiveHealthChecker{ + Send: &egv1a1.ActiveHealthCheckPayload{ + Type: egv1a1.ActiveHealthCheckPayloadTypeText, + Binary: []byte{'f', 'o', 'o'}, + }, + Receive: &egv1a1.ActiveHealthCheckPayload{ + Type: egv1a1.ActiveHealthCheckPayloadTypeText, + Text: ptr.To("foo"), + }, }, }, }, } }, wantErrors: []string{ - `spec.healthCheck.tcp.send: Invalid value: "object": If payload type is Text, text field needs to be set., spec.healthCheck.tcp.send: Invalid value: "object": If payload type is Binary, binary field needs to be set.`, + `spec.HealthCheck.active.tcp.send: Invalid value: "object": If payload type is Text, text field needs to be set., spec.HealthCheck.active.tcp.send: Invalid value: "object": If payload type is Binary, binary field needs to be set.`, }, }, { @@ -741,22 +761,24 @@ func TestBackendTrafficPolicyTarget(t *testing.T) { }, }, HealthCheck: &egv1a1.HealthCheck{ - Type: egv1a1.HealthCheckerTypeTCP, - TCP: &egv1a1.TCPHealthChecker{ - Send: &egv1a1.HealthCheckPayload{ - Type: egv1a1.HealthCheckPayloadTypeText, - Text: ptr.To("foo"), - }, - Receive: &egv1a1.HealthCheckPayload{ - Type: egv1a1.HealthCheckPayloadTypeText, - Binary: []byte{'f', 'o', 'o'}, + Active: &egv1a1.ActiveHealthCheck{ + Type: egv1a1.ActiveHealthCheckerTypeTCP, + TCP: &egv1a1.TCPActiveHealthChecker{ + Send: &egv1a1.ActiveHealthCheckPayload{ + Type: egv1a1.ActiveHealthCheckPayloadTypeText, + Text: ptr.To("foo"), + }, + Receive: &egv1a1.ActiveHealthCheckPayload{ + Type: egv1a1.ActiveHealthCheckPayloadTypeText, + Binary: []byte{'f', 'o', 'o'}, + }, }, }, }, } }, wantErrors: []string{ - `[spec.healthCheck.tcp.receive: Invalid value: "object": If payload type is Text, text field needs to be set., spec.healthCheck.tcp.receive: Invalid value: "object": If payload type is Binary, binary field needs to be set.]`, + `[spec.HealthCheck.active.tcp.receive: Invalid value: "object": If payload type is Text, text field needs to be set., spec.HealthCheck.active.tcp.receive: Invalid value: "object": If payload type is Binary, binary field needs to be set.]`, }, }, {