Improve EndpointController's handling of headless services under dual-stack
EndpointController was accidentally requiring all headless services to be IPv4-only in clusters with IPv6DualStack enabled. This still leaves "legacy" (ie, IPFamily-less) headless services as always IPv4-only because the controller doesn't currently have easy access to the information that would allow it to fix that. (EndpointSliceController had the same problem already, and still does.) This can be fixed, if needed, by manually setting IPFamily, and the proposed API for 1.20 will handle this situation better.
This commit is contained in:
@@ -32,8 +32,10 @@ import (
|
||||
v1listers "k8s.io/client-go/listers/core/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
"k8s.io/kubernetes/pkg/util/hash"
|
||||
utilnet "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
// ServiceSelectorCache is a cache of service selectors to avoid high CPU consumption caused by frequent calls to AsSelectorPreValidated (see #73527)
|
||||
@@ -275,3 +277,18 @@ func (sl portsInOrder) Less(i, j int) bool {
|
||||
h2 := DeepHashObjectToString(sl[j])
|
||||
return h1 < h2
|
||||
}
|
||||
|
||||
// IsIPv6Service checks if svc should have IPv6 endpoints
|
||||
func IsIPv6Service(svc *v1.Service) bool {
|
||||
if helper.IsServiceIPSet(svc) {
|
||||
return utilnet.IsIPv6String(svc.Spec.ClusterIP)
|
||||
} else if svc.Spec.IPFamily != nil {
|
||||
return *svc.Spec.IPFamily == v1.IPv6Protocol
|
||||
} else {
|
||||
// FIXME: for legacy headless Services with no IPFamily, the current
|
||||
// thinking is that we should use the cluster default. Unfortunately
|
||||
// the endpoint controller doesn't know the cluster default. For now,
|
||||
// assume it's IPv4.
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user