in pkg/providers/translation/apisix_upstream.go [210:310]
func (t *translator) translateUpstreamActiveHealthCheckV2(config *configv2.ActiveHealthCheck) (*apisixv1.UpstreamActiveHealthCheck, error) {
var active apisixv1.UpstreamActiveHealthCheck
switch config.Type {
case apisixv1.HealthCheckHTTP, apisixv1.HealthCheckHTTPS, apisixv1.HealthCheckTCP:
active.Type = config.Type
case "":
active.Type = apisixv1.HealthCheckHTTP
default:
return nil, &TranslateError{
Field: "healthCheck.active.Type",
Reason: "invalid value",
}
}
active.Timeout = int(config.Timeout.Seconds())
if config.Port < 0 || config.Port > 65535 {
return nil, &TranslateError{
Field: "healthCheck.active.port",
Reason: "invalid value",
}
} else {
active.Port = config.Port
}
if config.Concurrency < 0 {
return nil, &TranslateError{
Field: "healthCheck.active.concurrency",
Reason: "invalid value",
}
} else {
active.Concurrency = config.Concurrency
}
active.Host = config.Host
active.HTTPPath = config.HTTPPath
active.HTTPRequestHeaders = config.RequestHeaders
if config.StrictTLS == nil || *config.StrictTLS {
active.HTTPSVerifyCert = true
}
if config.Healthy != nil {
if config.Healthy.Successes < 0 || config.Healthy.Successes > apisixv1.HealthCheckMaxConsecutiveNumber {
return nil, &TranslateError{
Field: "healthCheck.active.healthy.successes",
Reason: "invalid value",
}
}
active.Healthy.Successes = config.Healthy.Successes
if config.Healthy.HTTPCodes != nil && len(config.Healthy.HTTPCodes) < 1 {
return nil, &TranslateError{
Field: "healthCheck.active.healthy.httpCodes",
Reason: "empty",
}
}
active.Healthy.HTTPStatuses = config.Healthy.HTTPCodes
if config.Healthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
return nil, &TranslateError{
Field: "healthCheck.active.healthy.interval",
Reason: "invalid value",
}
}
active.Healthy.Interval = int(config.Healthy.Interval.Seconds())
}
if config.Unhealthy != nil {
if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
return nil, &TranslateError{
Field: "healthCheck.active.unhealthy.httpFailures",
Reason: "invalid value",
}
}
active.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures
if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apisixv1.HealthCheckMaxConsecutiveNumber {
return nil, &TranslateError{
Field: "healthCheck.active.unhealthy.tcpFailures",
Reason: "invalid value",
}
}
active.Unhealthy.TCPFailures = config.Unhealthy.TCPFailures
active.Unhealthy.Timeouts = config.Unhealthy.Timeouts
if config.Unhealthy.HTTPCodes != nil && len(config.Unhealthy.HTTPCodes) < 1 {
return nil, &TranslateError{
Field: "healthCheck.active.unhealthy.httpCodes",
Reason: "empty",
}
}
active.Unhealthy.HTTPStatuses = config.Unhealthy.HTTPCodes
if config.Unhealthy.Interval.Duration < apisixv1.ActiveHealthCheckMinInterval {
return nil, &TranslateError{
Field: "healthCheck.active.unhealthy.interval",
Reason: "invalid value",
}
}
active.Unhealthy.Interval = int(config.Unhealthy.Interval.Seconds())
}
return &active, nil
}