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:
parent
302434e392
commit
51c05679e6
14 changed files with 204 additions and 111 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue