MON-4501: Migrate Prometheus targets discovering from Endpoints to EndpointSlices#1357
MON-4501: Migrate Prometheus targets discovering from Endpoints to EndpointSlices#1357machine424 wants to merge 2 commits intoopenshift:masterfrom
Conversation
|
Skipping CI for Draft Pull Request. |
|
@machine424: This pull request references MON-4501 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/lgtm |
|
/retest-required |
|
I imagine you want to set cluster-ingress-operator/pkg/operator/controller/ingress/monitoring.go Lines 54 to 107 in 4d7cbb0 |
|
By the way, if you don't mind, please copy the description and Jira link into the commit message. |
|
/hold There are some more changes to be done: |
|
New changes are detected. LGTM label has been removed. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe changes add support for EndpointSlice-based service discovery by granting RBAC access to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
…rviceDiscoveryRole: EndpointSlice in ServiceMonitors
This PR migrates Prometheus service discovery from the deprecated Endpoints API to the EndpointSlices API, by:
Setting serviceDiscoveryRole: EndpointSlice on ServiceMonitors.
Granting Prometheus endpointslices permissions.
We're taking a conservative approach by keeping the existing endpoints permissions alongside the new endpointslices ones. This provides a safety net in case any ServiceMonitors, whether deployed from this repo or from another source, still rely on the same Role and were missed during the migration.
That said, since both resources provide essentially the same data, keeping both isn't meaningfully more permissive from a security standpoint.
These changes target OpenShift 4.22+ and should not be backported to earlier releases.
Due to the scope of changes across multiple repositories, these modifications were generated with Claude assistance.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/operator/controller/ingress/monitoring_test.go (1)
55-62: Strengthen this test to assert the expected default value, not only “changed”.Right now, this can still pass even if
desiredServiceMonitorstops settingserviceDiscoveryRoletoEndpointSlice. Add an explicit baseline assertion before mutating.Suggested test hardening
// Verify that changing serviceDiscoveryRole is detected as a change. sm4 := desiredServiceMonitor(ic, svc, deploymentRef) + val, found, err := unstructured.NestedString(sm1.Object, "spec", "serviceDiscoveryRole") + if err != nil { + t.Fatalf("failed to read servicemonitor serviceDiscoveryRole: %v", err) + } + if !found || val != "EndpointSlice" { + t.Fatalf("expected serviceDiscoveryRole to be EndpointSlice, got found=%t val=%q", found, val) + } if err := unstructured.SetNestedField(sm4.Object, "Endpoints", "spec", "serviceDiscoveryRole"); err != nil { t.Fatalf("failed to mutate servicemonitor: %v", err) }As per coding guidelines, "-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/operator/controller/ingress/monitoring_test.go` around lines 55 - 62, Add a baseline assertion that the generated ServiceMonitor has the expected default serviceDiscoveryRole before you mutate it: use desiredServiceMonitor(...) to produce sm4, read the nested field (e.g., via unstructured.NestedString(sm4.Object, "spec", "serviceDiscoveryRole")) and assert it equals "EndpointSlice" (or the expected default) so the test fails if defaulting stops setting that value; then proceed with the existing mutation and serviceMonitorChanged check. Reference: desiredServiceMonitor, sm4, serviceMonitorChanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/operator/controller/ingress/monitoring_test.go`:
- Around line 55-62: Add a baseline assertion that the generated ServiceMonitor
has the expected default serviceDiscoveryRole before you mutate it: use
desiredServiceMonitor(...) to produce sm4, read the nested field (e.g., via
unstructured.NestedString(sm4.Object, "spec", "serviceDiscoveryRole")) and
assert it equals "EndpointSlice" (or the expected default) so the test fails if
defaulting stops setting that value; then proceed with the existing mutation and
serviceMonitorChanged check. Reference: desiredServiceMonitor, sm4,
serviceMonitorChanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c2d61ccf-afdf-4dda-93a2-0b4bcc032207
📒 Files selected for processing (6)
manifests/0000_90_ingress-operator_00_prometheusrole.yamlmanifests/0000_90_ingress-operator_02_servicemonitor.yamlpkg/manifests/assets/router/metrics/role.yamlpkg/operator/controller/ingress/metrics.gopkg/operator/controller/ingress/monitoring.gopkg/operator/controller/ingress/monitoring_test.go
|
/retest-required |
|
/retest |
|
@machine424: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
This PR migrates Prometheus service discovery from the deprecated Endpoints API to the EndpointSlices API, by:
serviceDiscoveryRole: EndpointSliceon ServiceMonitors.endpointslicespermissions.We're taking a conservative approach by keeping the existing
endpointspermissions alongside the newendpointslicesones. This provides a safety net in case any ServiceMonitors, whether deployed from this repo or from another source, still rely on the same Role and were missed during the migration.That said, since both resources provide essentially the same data, keeping both isn't meaningfully more permissive from a security standpoint.
These changes target OpenShift 4.22+ and should not be backported to earlier releases.
Due to the scope of changes across multiple repositories, these modifications were generated with Claude assistance.