From d559a6c1600ff2744d56ceeef4b092dbf8c3ba00 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 25 Apr 2016 14:45:53 +0100 Subject: [PATCH] Show the k8s load balancer IP if it is set --- probe/kubernetes/reporter.go | 9 +++++---- probe/kubernetes/reporter_test.go | 5 +++-- probe/kubernetes/service.go | 9 +++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/probe/kubernetes/reporter.go b/probe/kubernetes/reporter.go index 45d646a02e..7010070e1c 100644 --- a/probe/kubernetes/reporter.go +++ b/probe/kubernetes/reporter.go @@ -23,10 +23,11 @@ var ( } ServiceMetadataTemplates = report.MetadataTemplates{ - ServiceID: {ID: ServiceID, Label: "ID", From: report.FromLatest, Priority: 1}, - Namespace: {ID: Namespace, Label: "Namespace", From: report.FromLatest, Priority: 2}, - ServiceCreated: {ID: ServiceCreated, Label: "Created", From: report.FromLatest, Priority: 3}, - ServiceIP: {ID: ServiceIP, Label: "Internal IP", From: report.FromLatest, Priority: 4}, + ServiceID: {ID: ServiceID, Label: "ID", From: report.FromLatest, Priority: 1}, + Namespace: {ID: Namespace, Label: "Namespace", From: report.FromLatest, Priority: 2}, + ServiceCreated: {ID: ServiceCreated, Label: "Created", From: report.FromLatest, Priority: 3}, + ServicePublicIP: {ID: ServicePublicIP, Label: "Public IP", From: report.FromLatest, Priority: 4}, + ServiceIP: {ID: ServiceIP, Label: "Internal IP", From: report.FromLatest, Priority: 5}, } PodTableTemplates = report.TableTemplates{ diff --git a/probe/kubernetes/reporter_test.go b/probe/kubernetes/reporter_test.go index 101ba70d18..a3610e7443 100644 --- a/probe/kubernetes/reporter_test.go +++ b/probe/kubernetes/reporter_test.go @@ -70,8 +70,9 @@ var ( CreationTimestamp: unversioned.Now(), }, Spec: api.ServiceSpec{ - Type: api.ServiceTypeLoadBalancer, - ClusterIP: "10.0.1.1", + Type: api.ServiceTypeLoadBalancer, + ClusterIP: "10.0.1.1", + LoadBalancerIP: "10.0.1.2", Ports: []api.ServicePort{ {Protocol: "TCP", Port: 6379}, }, diff --git a/probe/kubernetes/service.go b/probe/kubernetes/service.go index 37460adf56..d2bd38dfa8 100644 --- a/probe/kubernetes/service.go +++ b/probe/kubernetes/service.go @@ -14,6 +14,7 @@ const ( ServiceName = "kubernetes_service_name" ServiceCreated = "kubernetes_service_created" ServiceIP = "kubernetes_service_ip" + ServicePublicIP = "kubernetes_service_public_ip" ServiceLabelPrefix = "kubernetes_service_label_" ) @@ -55,11 +56,15 @@ func (s *service) Selector() labels.Selector { } func (s *service) GetNode() report.Node { - return report.MakeNodeWith(report.MakeServiceNodeID(s.Namespace(), s.Name()), map[string]string{ + latest := map[string]string{ ServiceID: s.ID(), ServiceName: s.Name(), ServiceCreated: s.ObjectMeta.CreationTimestamp.Format(time.RFC822), Namespace: s.Namespace(), ServiceIP: s.Spec.ClusterIP, - }).AddTable(ServiceLabelPrefix, s.Labels) + } + if s.Spec.LoadBalancerIP != "" { + latest[ServicePublicIP] = s.Spec.LoadBalancerIP + } + return report.MakeNodeWith(report.MakeServiceNodeID(s.Namespace(), s.Name()), latest).AddTable(ServiceLabelPrefix, s.Labels) }