Skip to content

Commit

Permalink
Merge pull request #36 from rsevilla87/optimize-pod-count
Browse files Browse the repository at this point in the history
Optimize GetCurrentPodCount() by listing pods only once
  • Loading branch information
vishnuchalla authored Nov 29, 2023
2 parents dc2da49 + c923ca5 commit d38a199
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ocp-metadata/ocp-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ func (meta *Metadata) GetCurrentPodCount() (int, error) {
if err != nil {
return podCount, err
}
for _, node := range nodeList.Items {
podList, err := meta.clientSet.CoreV1().Pods(metav1.NamespaceAll).List(context.TODO(), metav1.ListOptions{FieldSelector: "status.phase=Running,spec.nodeName=" + node.Name})
if err != nil {
return podCount, err
podList, err := meta.clientSet.CoreV1().Pods(metav1.NamespaceAll).List(context.TODO(), metav1.ListOptions{FieldSelector: "status.phase=Running"})
if err != nil {
return podCount, err
}
for _, pod := range podList.Items {
for _, node := range nodeList.Items {
if pod.Spec.NodeName == node.Name {
podCount++
break
}
}
podCount += len(podList.Items)
}
return podCount, nil
}
Expand Down

0 comments on commit d38a199

Please sign in to comment.