mirror of
https://github.com/coredns/coredns.git
synced 2025-12-06 02:15:11 -05:00
plugin/kubernetes: Add support for dual stack ClusterIP Services (#4339)
* support dual stack clusterIPs Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * stickler Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * fix ClusterIPs make Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
@@ -67,7 +67,7 @@ func (l *EndpointLatencyRecorder) record() {
|
||||
// don't change very often (comparing to much more frequent endpoints changes), cases when this method
|
||||
// will return wrong answer should be relatively rare. Because of that we intentionally accept this
|
||||
// flaw to keep the solution simple.
|
||||
isHeadless := len(l.Services) == 1 && l.Services[0].ClusterIP == api.ClusterIPNone
|
||||
isHeadless := len(l.Services) == 1 && l.Services[0].Headless()
|
||||
|
||||
if !isHeadless || l.TT.IsZero() {
|
||||
return
|
||||
|
||||
@@ -15,7 +15,7 @@ type Service struct {
|
||||
Name string
|
||||
Namespace string
|
||||
Index string
|
||||
ClusterIP string
|
||||
ClusterIPs []string
|
||||
Type api.ServiceType
|
||||
ExternalName string
|
||||
Ports []api.ServicePort
|
||||
@@ -40,13 +40,19 @@ func ToService(obj meta.Object) (meta.Object, error) {
|
||||
Name: svc.GetName(),
|
||||
Namespace: svc.GetNamespace(),
|
||||
Index: ServiceKey(svc.GetName(), svc.GetNamespace()),
|
||||
ClusterIP: svc.Spec.ClusterIP,
|
||||
Type: svc.Spec.Type,
|
||||
ExternalName: svc.Spec.ExternalName,
|
||||
|
||||
ExternalIPs: make([]string, len(svc.Status.LoadBalancer.Ingress)+len(svc.Spec.ExternalIPs)),
|
||||
}
|
||||
|
||||
if len(svc.Spec.ClusterIPs) > 0 {
|
||||
s.ClusterIPs = make([]string, len(svc.Spec.ClusterIPs))
|
||||
copy(s.ClusterIPs, svc.Spec.ClusterIPs)
|
||||
} else {
|
||||
s.ClusterIPs = []string{svc.Spec.ClusterIP}
|
||||
}
|
||||
|
||||
if len(svc.Spec.Ports) == 0 {
|
||||
// Add sentinel if there are no ports.
|
||||
s.Ports = []api.ServicePort{{Port: -1}}
|
||||
@@ -70,6 +76,11 @@ func ToService(obj meta.Object) (meta.Object, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Headless returns true if the service is headless
|
||||
func (s *Service) Headless() bool {
|
||||
return s.ClusterIPs[0] == api.ClusterIPNone
|
||||
}
|
||||
|
||||
var _ runtime.Object = &Service{}
|
||||
|
||||
// DeepCopyObject implements the ObjectKind interface.
|
||||
@@ -79,12 +90,13 @@ func (s *Service) DeepCopyObject() runtime.Object {
|
||||
Name: s.Name,
|
||||
Namespace: s.Namespace,
|
||||
Index: s.Index,
|
||||
ClusterIP: s.ClusterIP,
|
||||
Type: s.Type,
|
||||
ExternalName: s.ExternalName,
|
||||
ClusterIPs: make([]string, len(s.ClusterIPs)),
|
||||
Ports: make([]api.ServicePort, len(s.Ports)),
|
||||
ExternalIPs: make([]string, len(s.ExternalIPs)),
|
||||
}
|
||||
copy(s1.ClusterIPs, s.ClusterIPs)
|
||||
copy(s1.Ports, s.Ports)
|
||||
copy(s1.ExternalIPs, s.ExternalIPs)
|
||||
return s1
|
||||
|
||||
Reference in New Issue
Block a user