mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-21 18:11:22 +00:00
Refine NeedsHealthCheck logic
This commit is contained in:
@@ -70,19 +70,24 @@ func GetLoadBalancerSourceRanges(service *api.Service) (netsets.IPNet, error) {
|
||||
return ipnets, nil
|
||||
}
|
||||
|
||||
// NeedsHealthCheck Check service for health check annotations
|
||||
func NeedsHealthCheck(service *api.Service) bool {
|
||||
// RequestsOnlyLocalTraffic checks if service requests OnlyLocal traffic.
|
||||
func RequestsOnlyLocalTraffic(service *api.Service) bool {
|
||||
if service.Spec.Type != api.ServiceTypeLoadBalancer &&
|
||||
service.Spec.Type != api.ServiceTypeNodePort {
|
||||
return false
|
||||
}
|
||||
// First check the alpha annotation and then the beta. This is so existing
|
||||
// Services continue to work till the user decides to transition to beta.
|
||||
// If they transition to beta, there's no way to go back to alpha without
|
||||
// rolling back the cluster.
|
||||
for _, annotation := range []string{AlphaAnnotationExternalTraffic, BetaAnnotationExternalTraffic} {
|
||||
if l, ok := service.Annotations[annotation]; ok {
|
||||
if l == AnnotationValueExternalTrafficLocal {
|
||||
switch l {
|
||||
case AnnotationValueExternalTrafficLocal:
|
||||
return true
|
||||
} else if l == AnnotationValueExternalTrafficGlobal {
|
||||
case AnnotationValueExternalTrafficGlobal:
|
||||
return false
|
||||
} else {
|
||||
default:
|
||||
glog.Errorf("Invalid value for annotation %v: %v", annotation, l)
|
||||
}
|
||||
}
|
||||
@@ -90,6 +95,14 @@ func NeedsHealthCheck(service *api.Service) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// NeedsHealthCheck Check if service needs health check.
|
||||
func NeedsHealthCheck(service *api.Service) bool {
|
||||
if service.Spec.Type != api.ServiceTypeLoadBalancer {
|
||||
return false
|
||||
}
|
||||
return RequestsOnlyLocalTraffic(service)
|
||||
}
|
||||
|
||||
// GetServiceHealthCheckNodePort Return health check node port annotation for service, if one exists
|
||||
func GetServiceHealthCheckNodePort(service *api.Service) int32 {
|
||||
if !NeedsHealthCheck(service) {
|
||||
|
Reference in New Issue
Block a user