Skip to content

refactor: unify metricsGC controller init into controllers.go and add…#534

Open
KeyOfSpectator wants to merge 3 commits into
openkruise:masterfrom
KeyOfSpectator:refactor/metric-async-controller-20260612
Open

refactor: unify metricsGC controller init into controllers.go and add…#534
KeyOfSpectator wants to merge 3 commits into
openkruise:masterfrom
KeyOfSpectator:refactor/metric-async-controller-20260612

Conversation

@KeyOfSpectator

Copy link
Copy Markdown
Contributor

… 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.

Ⅰ. Describe what this PR does

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how to verify it

Ⅳ. Special notes for reviews

@kruise-bot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign furykerry for approval by writing /assign @furykerry in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.79%. Comparing base (ce4b897) to head (37f3f13).

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     
Flag Coverage Δ
unittests 79.79% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pkg/controller/linkname_test.go Outdated
// 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"}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@KeyOfSpectator KeyOfSpectator force-pushed the refactor/metric-async-controller-20260612 branch from c9a7ac4 to 37f3f13 Compare June 23, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants