Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: move healthCheck to healthCheck.active #2540

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions api/v1alpha1/healthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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"`
Expand Down
198 changes: 109 additions & 89 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading