Conversation
…nitor's own namespace
Prometheus Operator reads an empty NamespaceSelector as "the namespace this
ServiceMonitor is in". The check compared labels only on that path, so a
Service with matching labels in any other namespace satisfied the monitor and
the dangling one went unreported.
The namespace is now compared when no namespace selector is set. A manifest
that leaves the namespace out on either side carries nothing to compare - a
Helm template rendered without one, or a file meant to be applied with "-n" -
and keeps matching as before; that shape is what the "dont-fire" pair in
tests/checks/dangling-servicemonitor.yml uses.
Coverage:
- three unit cases: matching labels across two namespaces is now reported,
the same pair inside one namespace still matches, and a namespaceless
manifest still matches
- the e2e fixture gains the reported pair, and the bats case expects five
reports instead of four
Against main the first of those unit cases fails, which is the defect. With
this change the package is green, the whole pkg/templates tree is green, and
the reproduction from the issue reports the monitor while the issue's own
control - the Service moved into the monitor's namespace - stays clean.
Fixes stackrox#1256
Signed-off-by: Eljees <57435526+Eljees@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Central YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughThe dangling ServiceMonitor check now treats an empty namespace selector as the monitor namespace. Tests cover cross-namespace, same-namespace, and namespace-less resources. The end-to-end fixture and assertions include the additional diagnostic. ChangesDangling ServiceMonitor namespace matching
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1262 +/- ##
===========================================
- Coverage 62.36% 31.72% -30.64%
===========================================
Files 197 239 +42
Lines 4854 6594 +1740
===========================================
- Hits 3027 2092 -935
- Misses 1439 4326 +2887
+ Partials 388 176 -212
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The one red check here is The measurement is in #1242, and #1263 carries the two parts of it that do not need repository settings access. |
Fixes #1256.
The defect
Prometheus Operator reads an empty
NamespaceSelectoras "the namespace this ServiceMonitor is in".dangling-servicemonitorhad one branch that never looked at namespaces at all:A Service with matching labels in any namespace satisfied a monitor that set no namespace selector, so the dangling monitor in the report went unreported.
The change
The namespace is compared on that branch. A manifest that leaves the namespace out on either side carries nothing to compare - a Helm template rendered without one, or a file meant to be applied with
-n- and keeps matching as it did. That shape is not hypothetical: thedont-firepair intests/checks/dangling-servicemonitor.ymlis exactly it, a Service indontfirewith a ServiceMonitor that has no namespace, and it must keep passing.Red, then green
The new unit case fails on untouched
main:With the change:
go test ./pkg/templates/...is green throughout.The reproduction from the issue, through the built binary
and the control the issue names, the Service moved into
monitoring:e2e
tests/checks/dangling-servicemonitor.ymlgains that pair, so the fixture now produces five reports and the bats case asserts the fifth message and a count of five. Run against the built binary:AI-assisted (LLM used for drafting); every change verified and tested by me.