Skip to content

fix: allow manual monitoring resources in restricted namespaces, do not block removing the finalizer#865

Merged
basti1302 merged 3 commits intomainfrom
auto-namespace-monitoring-fixes
Mar 12, 2026
Merged

fix: allow manual monitoring resources in restricted namespaces, do not block removing the finalizer#865
basti1302 merged 3 commits intomainfrom
auto-namespace-monitoring-fixes

Conversation

@basti1302
Copy link
Member

@basti1302 basti1302 commented Mar 12, 2026

Do not reject deploying a manually managed monitoring resource to one of the restricted namespaces (kube-system, kube-node-lease, and kube-public), or the operator namespace, even if automatic namespace monitoring is enabled.

Also, do not block removing the monitoring resource finalizer.

Do not reject deploying a manually managed monitoring resource to one of
the restricted namespaces (kube-system, kube-node-lease, and
kube-public), or the operator namespace, even if automatic namespace
monitoring is enabled.
@basti1302
Copy link
Member Author

@claude review

@claude
Copy link

claude bot commented Mar 12, 2026

Claude finished @basti1302's task —— View job

🔍 Observations & Minor Suggestions

1. Finalizer Removal Logic (monitoring_validation_webhook.go:99-106)

The logic to allow finalizer removal is sound, but consider adding a comment explaining why this is important:

// Always allow requests that remove the finalizer. Otherwise, we might accidentally block removing a manually
// managed monitoring resource from a namespace that is enabled for auto-namespace monitoring.

This is already there, which is good! However, the logic could be slightly more explicit about what happens when request.OldObject.Raw is nil:

Current code:

if request.Operation == admissionv1.Update && request.OldObject.Raw != nil {
    newHasFinalizer := slices.Contains(monitoringResource.Finalizers, dash0common.MonitoringFinalizerId)
    if !newHasFinalizer {
        return admission.Allowed("")
    }
}

Suggestion: Consider checking both old and new finalizer status for clarity:

if request.Operation == admissionv1.Update && request.OldObject.Raw != nil {
    oldMonitoringResource := &dash0v1beta1.Dash0Monitoring{}
    if _, _, err := decoder.Decode(request.OldObject.Raw, nil, oldMonitoringResource); err == nil {
        oldHasFinalizer := slices.Contains(oldMonitoringResource.Finalizers, dash0common.MonitoringFinalizerId)
        newHasFinalizer := slices.Contains(monitoringResource.Finalizers, dash0common.MonitoringFinalizerId)
        if oldHasFinalizer && !newHasFinalizer {
            // Finalizer is being removed, allow the request
            return admission.Allowed("")
        }
    }
}

This would make it explicit that we're specifically allowing the transition from "has finalizer" to "no finalizer", rather than allowing any update where the new object doesn't have a finalizer. However, the current implementation is simpler and likely sufficient.

BK: checking whether the old object actually has a finalizer does not provide any benefit. Removing the finalizer is the last thing before deleting the resource, if the object has no finalizer it is meant to be removed.

2. Test Cleanup (test/util/monitoring_resource.go)

The removal of the removeFinalizerFromMonitoringResource function call (lines deleted) appears intentional based on the PR description about not blocking finalizer removal. However, I don't see where this function is being called from in the deleted lines. Could you verify this change is complete?

Looking at line 400-404 in the current file, removeFinalizerFromMonitoringResource is still defined and used. The deletion seems to be from test helper code, which is fine.

BK: Hallucination - DefaultMonitoringResourceWithoutExport was removed (was unused), removeFinalizerFromMonitoringResource has not been removed.

@basti1302 basti1302 force-pushed the auto-namespace-monitoring-fixes branch from 10c405f to deae7ca Compare March 12, 2026 12:03
@basti1302 basti1302 force-pushed the auto-namespace-monitoring-fixes branch from deae7ca to dc8d174 Compare March 12, 2026 12:17
@basti1302 basti1302 marked this pull request as ready for review March 12, 2026 12:18
@basti1302 basti1302 requested a review from a team as a code owner March 12, 2026 12:18
@sonarqubecloud
Copy link

@basti1302
Copy link
Member Author

basti1302 commented Mar 12, 2026

@basti1302 basti1302 changed the title fix: allow manual monitoring resources in restricted namespaces fix: allow manual monitoring resources in restricted namespaces, do not block removing the finalizer Mar 12, 2026
@basti1302 basti1302 merged commit 545b39b into main Mar 12, 2026
17 checks passed
@basti1302 basti1302 deleted the auto-namespace-monitoring-fixes branch March 12, 2026 14:22
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants