AlinsRan commented on code in PR #2574: URL: https://github.com/apache/apisix-ingress-controller/pull/2574#discussion_r2375281471
########## internal/adc/translator/apisixupstream.go: ########## @@ -252,3 +253,118 @@ func translateApisixUpstreamExternalNodesService(tctx *provider.TranslateContext return nil } + +func translateUpstreamHealthCheck(au *apiv2.ApisixUpstream, ups *adc.Upstream) error { + if au == nil { + return nil + } + healcheck := au.Spec.HealthCheck + if healcheck == nil || (healcheck.Passive == nil && healcheck.Active == nil) { + return nil + } + var hc adc.UpstreamHealthCheck + if healcheck.Passive != nil { + passive, err := translateUpstreamPassiveHealthCheck(healcheck.Passive) + if err != nil { + return err + } + hc.Passive = passive + } + + if healcheck.Active != nil { + active, err := translateUpstreamActiveHealthCheck(healcheck.Active) + if err != nil { + return err + } + hc.Active = active + } + + ups.Checks = &hc + return nil +} + +func translateUpstreamActiveHealthCheck(config *apiv2.ActiveHealthCheck) (*adc.UpstreamActiveHealthCheck, error) { + var active adc.UpstreamActiveHealthCheck + switch config.Type { + case apiv2.HealthCheckHTTP, apiv2.HealthCheckHTTPS, apiv2.HealthCheckTCP: + active.Type = config.Type + case "": + active.Type = apiv2.HealthCheckHTTP + default: + return nil, fmt.Errorf(`"healthCheck.active.Type" has invalid value`) + } + + active.Timeout = int(config.Timeout.Seconds()) + active.Port = config.Port + 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 { + active.Healthy.Successes = config.Healthy.Successes + active.Healthy.HTTPStatuses = config.Healthy.HTTPCodes + + if config.Healthy.Interval.Duration < apiv2.ActiveHealthCheckMinInterval { + return nil, fmt.Errorf(`"healthCheck.active.healthy.interval" has invalid value`) + } + active.Healthy.Interval = int(config.Healthy.Interval.Seconds()) + } + + if config.Unhealthy != nil { + if config.Unhealthy.HTTPFailures < 0 || config.Unhealthy.HTTPFailures > apiv2.HealthCheckMaxConsecutiveNumber { + return nil, fmt.Errorf(`"healthCheck.active.unhealthy.httpFailures" has invalid value`) + } + active.Unhealthy.HTTPFailures = config.Unhealthy.HTTPFailures + + if config.Unhealthy.TCPFailures < 0 || config.Unhealthy.TCPFailures > apiv2.HealthCheckMaxConsecutiveNumber { + return nil, fmt.Errorf(`"healthCheck.active.unhealthy.tcpFailures" has 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, fmt.Errorf(`"healthCheck.active.unhealthy.httpCodes" is empty`) + } Review Comment: <img width="1624" height="232" alt="image" src="https://github.com/user-attachments/assets/73d14e44-f9a3-4b32-809e-3e7d4ed80f67" /> I don't think it's necessary. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org