Merge pull request #107 from rbtr/list-running-pods

only list running pods
This commit is contained in:
Mikolaj Pawlikowski
2021-11-08 15:41:13 +00:00
committed by GitHub
2 changed files with 6 additions and 6 deletions
-4
View File
@@ -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"),
+6 -2
View File
@@ -96,7 +96,11 @@ func getPodIP(p v1.Pod) 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(context.TODO(), 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(context.TODO(), listOpts)
if err != nil {
zap.L().Error("Error getting pods for selector", zap.String("selector", GoldpingerConfig.LabelSelector), zap.Error(err))
CountError("kubernetes_api")
@@ -104,7 +108,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,