Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Clear EndpointStatuses for PodMonitoring without endpoints #1197

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

hsmatulisgoogle
Copy link
Collaborator

Clear EndPointStatuses when PodMonitoring does not have an endpoint.

This fixes a bug where PodMonitorings without any endpoints have a stale list of endpoints.

@hsmatulisgoogle hsmatulisgoogle force-pushed the hmatulis-target-status-dropping branch 2 times, most recently from a76eb6e to 6134c5e Compare December 3, 2024 23:08
@hsmatulisgoogle
Copy link
Collaborator Author

Note that this PR also fixes a misconfigured test that was silently failing (#1097 adds support for a nodepool format with caadvisor)

@hsmatulisgoogle hsmatulisgoogle force-pushed the hmatulis-target-status-dropping branch from 6134c5e to 59c0c2e Compare December 4, 2024 15:53
Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice! This is great and definitely one way of doing this.

I wonder if it wouldn't be better to do this on reconcile PodMonitoring loop - because the moment PodMonitoring changes, it triggers reconcile so we could automatically clear the status there. This would avoid extra API calls essentially

Actually I think I misunderstood the intention. I thought you are solving case of empty endpoint field. I think it's about no target situation (e.g. pods not selected). Let me re-review.

podMonitorings, err := getPodMonitoringCRDs(ctx, kubeClient)
if err != nil {
return err
} else if len(podMonitorings) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
} else if len(podMonitorings) == 0 {
}
if len(podMonitorings) == 0 {

@@ -335,6 +350,19 @@ func updateTargetStatus(ctx context.Context, logger logr.Logger, kubeClient clie
}
}

// Any pod monitorings that exist but dont have endpoints should also be updated
Copy link
Collaborator

@bwplotka bwplotka Dec 4, 2024

Choose a reason for hiding this comment

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

Suggested change
// Any pod monitorings that exist but dont have endpoints should also be updated
// Any pod monitorings that exist but don't have endpoints should also be updated.

Comment on lines 355 to 356
_, exists := hasEndpoints[pm.GetName()]
if !exists {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
_, exists := hasEndpoints[pm.GetName()]
if !exists {
if _, exists := hasEndpoints[pm.GetName()]; !exists {

if !exists {
pm.GetPodMonitoringStatus().EndpointStatuses = []monitoringv1.ScrapeEndpointStatus{}
if err := patchPodMonitoringStatus(ctx, kubeClient, pm, pm.GetPodMonitoringStatus()); err != nil {
// Same reasoning as above for error handling
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Same reasoning as above for error handling
// Same reasoning as above for error handling.

Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

LGTM, some ideas for a bit more efficiency and readable, otherwise LGTM, thanks!

pkg/operator/target_status.go Outdated Show resolved Hide resolved
pkg/operator/target_status.go Outdated Show resolved Hide resolved
pkg/operator/target_status.go Outdated Show resolved Hide resolved
pkg/operator/target_status.go Outdated Show resolved Hide resolved
pkg/operator/target_status.go Outdated Show resolved Hide resolved
@hsmatulisgoogle hsmatulisgoogle force-pushed the hmatulis-target-status-dropping branch from 59c0c2e to 35d70b2 Compare December 16, 2024 22:37
@hsmatulisgoogle hsmatulisgoogle force-pushed the hmatulis-target-status-dropping branch from 35d70b2 to a342d9b Compare December 16, 2024 22:41
@hsmatulisgoogle hsmatulisgoogle merged commit 903f7ec into main Dec 17, 2024
27 checks passed
@hsmatulisgoogle hsmatulisgoogle deleted the hmatulis-target-status-dropping branch December 17, 2024 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants