aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/object
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/kubernetes/object')
-rw-r--r--plugin/kubernetes/object/metrics.go2
-rw-r--r--plugin/kubernetes/object/service.go18
2 files changed, 16 insertions, 4 deletions
diff --git a/plugin/kubernetes/object/metrics.go b/plugin/kubernetes/object/metrics.go
index 929925cf1..f39744b8a 100644
--- a/plugin/kubernetes/object/metrics.go
+++ b/plugin/kubernetes/object/metrics.go
@@ -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
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