From 980a85b04dff1213609922240d493f525b758e41 Mon Sep 17 00:00:00 2001 From: Evan Baker Date: Mon, 23 Aug 2021 12:47:51 -0500 Subject: [PATCH] only list running pods Signed-off-by: Evan Baker --- pkg/goldpinger/client.go | 4 ---- pkg/goldpinger/k8s.go | 8 ++++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/goldpinger/client.go b/pkg/goldpinger/client.go index 14905d2..1238a21 100644 --- a/pkg/goldpinger/client.go +++ b/pkg/goldpinger/client.go @@ -57,7 +57,6 @@ func CheckNeighboursNeighbours(ctx context.Context) *models.CheckAllResults { // CheckCluster does a CheckNeighboursNeighbours and analyses results to produce a binary OK or not OK func CheckCluster(ctx context.Context) *models.ClusterHealthResults { - start := time.Now() output := models.ClusterHealthResults{ GeneratedAt: strfmt.DateTime(start), @@ -156,7 +155,6 @@ type CheckServicePodsResult struct { // CheckAllPods calls all neighbours and returns a detailed report func CheckAllPods(checkAllCtx context.Context, pods map[string]*GoldpingerPod) *models.CheckAllResults { - result := models.CheckAllResults{Responses: make(map[string]models.CheckAllPodResult)} ch := make(chan CheckServicePodsResult, len(pods)) @@ -164,9 +162,7 @@ func CheckAllPods(checkAllCtx context.Context, pods map[string]*GoldpingerPod) * wg.Add(len(pods)) for _, pod := range pods { - go func(pod *GoldpingerPod) { - // logger logger := zap.L().With( zap.String("op", "check"), diff --git a/pkg/goldpinger/k8s.go b/pkg/goldpinger/k8s.go index 05b6be4..1c5b130 100644 --- a/pkg/goldpinger/k8s.go +++ b/pkg/goldpinger/k8s.go @@ -44,7 +44,11 @@ func getPodNamespace() string { // GetAllPods returns a mapping from a pod name to a pointer to a GoldpingerPod(s) func GetAllPods() map[string]*GoldpingerPod { timer := GetLabeledKubernetesCallsTimer() - pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods(*GoldpingerConfig.Namespace).List(metav1.ListOptions{LabelSelector: GoldpingerConfig.LabelSelector}) + listOpts := metav1.ListOptions{ + LabelSelector: GoldpingerConfig.LabelSelector, + FieldSelector: "status.phase=Running", // only select Running pods, otherwise we will get them before they have IPs + } + pods, err := GoldpingerConfig.KubernetesClient.CoreV1().Pods(*GoldpingerConfig.Namespace).List(listOpts) if err != nil { zap.L().Error("Error getting pods for selector", zap.String("selector", GoldpingerConfig.LabelSelector), zap.Error(err)) CountError("kubernetes_api") @@ -52,7 +56,7 @@ func GetAllPods() map[string]*GoldpingerPod { timer.ObserveDuration() } - var podMap = make(map[string]*GoldpingerPod) + podMap := make(map[string]*GoldpingerPod) for _, pod := range pods.Items { podMap[pod.Name] = &GoldpingerPod{ Name: pod.Name,