Open
Conversation
Signed-off-by: Alex Castilio dos Santos <alexsantos@microsoft.com>
Signed-off-by: Alex Castilio dos Santos <alexsantos@microsoft.com>
Signed-off-by: Alex Castilio dos Santos <alexsantos@microsoft.com>
Retina Code Coverage ReportTotal coverage increased from
|
| Impacted Files | Coverage | |
|---|---|---|
| pkg/module/metrics/metrics_module.go | 64.59% ... 83.38% (18.79%) |
⬆️ |
| pkg/controllers/cache/cache.go | 65.35% ... 85.4% (20.05%) |
⬆️ |
6 tasks
aanchal22
reviewed
Mar 16, 2026
agrawaliti
approved these changes
Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix: Namespace Exclude Filtering in MetricConfiguration CRD
Problem
The namespace exclude filtering feature in the MetricConfiguration CRD is completely non-functional due to two separate bugs:
appendExcludeList()is empty — The function body contains only a TODO comment and never populates the exclude map or manages the filtermanager. Settingspec.namespaces.excludehas no effect.updateNamespaceLists()has logic errors — Sequentialifstatements instead ofif/elsecause both include and exclude lists to be reset when only one should be active.This means any cluster using
spec.namespaces.excludein a MetricsConfiguration CRD gets no namespace filtering at all — either no IPs are added to the filtermap (no metrics collected) or all IPs are added without filtering (eBPF map exhaustion).Fix
Three changes in
pkg/module/metrics/metrics_module.go:Implement
appendExcludeList()— Mirrors the existingappendIncludeList()pattern: diffs old vs new exclude set, removes IPs for newly-excluded namespaces from filtermanager, adds IPs for newly-un-excluded namespaces. On initial activation of exclude mode, usesGetAllNamespaces()to add IPs for all non-excluded namespaces.Fix
updateNamespaceLists()control flow — Replaced four sequentialifblocks with a properif/else if/elsechain. Addedreturnafter the both-set error case to prevent state mutation. Clears the opposite mode before activating the new one to avoid filtermanager entry conflicts.Add doc comment to
nsOfInterest()— Clarifies that when no namespace filters are configured, no namespace is considered of interest by default — pods must be individually annotated or already in the filtermap.One change in
pkg/controllers/cache/:GetAllNamespaces()toCacheInterface— Returns all unique namespaces that have at least one endpoint in the cache. Needed byappendExcludeList()to compute the set of non-excluded namespaces when exclude mode activates. IteratesepMapsincensMapis unused.Tests
Unit tests added covering:
TestNsOfInterest— Verifies correct behavior for include-only, exclude-only, and no-filter cases (6 subcases)TestAppendExcludeList— Mirrors existingTestAppendIncludeList: add, change, remove exclude namespaces (5 subcases)TestUpdateNamespaceListsExclude— Exclude-only spec populatesexcludedNamespacesand clearsincludedNamespacesTestPodCallBackExclude— End-to-end: pod in non-excluded ns is tracked, pod in excluded ns is notTestGetAllNamespaces— Cache returns unique namespace list from endpoint mapAll existing tests pass (no regressions).
Manual test
Scenario 1 — Namespace exclude filtering (MetricsConfiguration CRD mode)
Test:
Logs:
Scenario 2 — Switch from exclude to include
Test:
Update MetricsConfiguration CRD from namespaces.exclude: [test-exclude] to namespaces.include: [test-include] # → Verify: "Including namespaces|Appending namespaces|newly excluded|newly un-excluded" logLogs:
Related Issue
Fixes #2085
Checklist
git commit -S -s ...). See this documentation on signing commits.Screenshots (if applicable) or Testing Completed
Please add any relevant screenshots or GIFs to showcase the changes made.
Additional Notes
Add any additional notes or context about the pull request here.
Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.