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:
Chris O'Haver 2020-12-21 05:30:24 -05:00 committed by GitHub
parent 302434e392
commit 51c05679e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 204 additions and 111 deletions

View file

@ -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