refactor: unify metricsGC controller init into controllers.go and add…#534
Conversation
|
[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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #534 +/- ##
==========================================
+ Coverage 79.71% 79.79% +0.07%
==========================================
Files 195 195
Lines 14107 14110 +3
==========================================
+ Hits 11246 11259 +13
+ Misses 2457 2452 -5
+ Partials 404 399 -5
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:
|
| // fake discovery client built by installFakeGenericClient reports each kind | ||
| // in this slice as discoverable, so every guarded sub-controller proceeds | ||
| // past its discovery check. | ||
| var allAgentsKinds = []string{"Sandbox", "SandboxSet", "SandboxClaim", "SandboxUpdateOps"} |
There was a problem hiding this comment.
plz add SandboxTemplate, Checkpoint
| // would otherwise be unreachable from a single test binary. | ||
| // | ||
| //go:linkname controllerRuntimeUsedNames sigs.k8s.io/controller-runtime/pkg/controller.usedNames | ||
| var controllerRuntimeUsedNames sets.Set[string] |
There was a problem hiding this comment.
why access the package private variables ?
… E2E tests - Move sandboxmetricsgc.Reconciler creation and registration from main.go into pkg/controller.SetupWithManager, making it consistent with other controller registration patterns. - Replace Deps.MetricsCleanup (sandbox.Enqueuer) with Deps.MetricsGCOptions (sandboxmetricsgc.Options) so main.go only passes configuration. - Unify error wrapping style across all controller Add calls. - Add E2E tests (test/e2e/sandbox_metrics_gc_test.go) covering: single sandbox deletion metrics cleanup, bulk deletion via SandboxSet, and GC controller self-observability (controller-runtime reconcile metrics). - Add metrics_helper_test.go with ProxyGet-based /metrics fetching and expfmt-based metric parsing utilities for E2E assertions. - Promote github.com/prometheus/common from indirect to direct dependency for expfmt usage in E2E tests. Signed-off-by: 行疾 <shichun.fsc@alibaba-inc.com>
The controller-runtime metrics server with --metrics-bind-address=:8443 and secure serving enabled rejects anonymous requests via pods/proxy because kube-apiserver does not forward client certificates to upstream pods. This causes all E2E tests using fetchControllerMetrics() to fail with 401 Unauthorized in Kind clusters. Switch to HTTP on port 8080 with --metrics-secure=false. Access control is handled by NetworkPolicy (config/network-policy/) which is the recommended approach for non-production environments. Changes: - config/default/manager_metrics_patch.yaml: bind :8080, disable secure - test/e2e/metrics_helper_test.go: update scheme/port constants - config/default/kustomization.yaml: sync comment block Signed-off-by: 行疾 <shichun.fsc@alibaba-inc.com>
Add comprehensive table-driven tests covering all code paths in SetupWithManager including metricsGC registration, error wrapping for all sub-controller Add calls, and the metricsGC registration failure path. Use go:linkname to access controller-runtime's internal used-names registry for deterministic controller name collision testing without flaky timing dependencies. Coverage: pkg/controller/controllers.go SetupWithManager 100% Signed-off-by: 行疾 <shichun.fsc@alibaba-inc.com>
c9a7ac4 to
37f3f13
Compare
… E2E tests
Ⅰ. Describe what this PR does
Ⅱ. Does this pull request fix one issue?
Ⅲ. Describe how to verify it
Ⅳ. Special notes for reviews