Skip to content

Add labelSelector argument to GetCurrentPodCount#61

Merged
rsevilla87 merged 3 commits intocloud-bulldozer:mainfrom
rsevilla87:label-selector-nodes
Dec 16, 2025
Merged

Add labelSelector argument to GetCurrentPodCount#61
rsevilla87 merged 3 commits intocloud-bulldozer:mainfrom
rsevilla87:label-selector-nodes

Conversation

@rsevilla87
Copy link
Member

@rsevilla87 rsevilla87 commented Dec 15, 2025

Type of change

  • New feature

Description

Updating the GetCurrentPodCount() method to accept a labelSelector argument.

cc @ygalblum @jtaleric

Related Tickets & Documents

Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
@rsevilla87 rsevilla87 added the enhancement New feature or request label Dec 15, 2025
@rsevilla87 rsevilla87 requested a review from jtaleric December 15, 2025 11:27
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.01%. Comparing base (6ec7add) to head (ad2ec64).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   80.86%   82.01%   +1.15%     
==========================================
  Files          10       10              
  Lines         486      406      -80     
==========================================
- Hits          393      333      -60     
+ Misses         71       51      -20     
  Partials       22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rsevilla87 rsevilla87 changed the title labelSelector argument to GetCurrentPodCount Add labelSelector argument to GetCurrentPodCount Dec 15, 2025
// GetCurrentPodCount returns the number of current running pods across all worker nodes
func (meta *Metadata) GetCurrentPodCount() (int, error) {
// GetCurrentPodCount returns the number of running pods across on nodes matching the given labelSelector
func (meta *Metadata) GetCurrentPodCount(labelSelector string) (int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should rename the parameter to indicate that the labelSelector is for the nodes. Otherwise, since the function is called GetCurrentPodCount it's easy to assume the selector is for the pods. Something link nodesLabelSelector

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're changing this function, consider bettering it by making a map from the list of names allowing for an O(1) search instead of the inner loop

Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
Copy link
Contributor

@ygalblum ygalblum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits :)

func (meta *Metadata) GetCurrentPodCount(nodeLabelSelector string) (int, error) {
var podCount int
nodeList, err := meta.connector.ClientSet().CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector})
mapList := make(map[string]bool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move the declaration of mapList to after you know its size (before the loop). Then you can initialize it this way:

mapList := make(map[string]bool, len(nodeList.Items))

podCount++
break
}
if _, ok := mapList[pod.Spec.NodeName]; !ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you defined mapList as map[string]bool you don't need to check ok. You can just do:

if mapList[pod.Spec.NodeName] {

Copy link
Member Author

@rsevilla87 rsevilla87 Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right!, I renamed the variable to nodeMap as well, not sure why I wrote mapList

Signed-off-by: Raul Sevilla <rsevilla@redhat.com>
Copy link
Contributor

@ygalblum ygalblum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rsevilla87 rsevilla87 merged commit 1954654 into cloud-bulldozer:main Dec 16, 2025
6 checks passed
@rsevilla87 rsevilla87 deleted the label-selector-nodes branch January 8, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants