diff options
Diffstat (limited to 'plugin/kubernetes/object/service.go')
-rw-r--r-- | plugin/kubernetes/object/service.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/plugin/kubernetes/object/service.go b/plugin/kubernetes/object/service.go index be1404ea0..812b272e2 100644 --- a/plugin/kubernetes/object/service.go +++ b/plugin/kubernetes/object/service.go @@ -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 |