Skip to content

Improve error context for controller startup failures#2341

Open
Kunal1522 wants to merge 2 commits intoopenkruise:masterfrom
Kunal1522:feat/improve-startup-error-context
Open

Improve error context for controller startup failures#2341
Kunal1522 wants to merge 2 commits intoopenkruise:masterfrom
Kunal1522:feat/improve-startup-error-context

Conversation

@Kunal1522
Copy link
Contributor

Fixes #2340
Add error wrapping with context to controller initialization errors to improve debugging of startup failures. This helps operators quickly identify which controller failed during initialization without grepping through code.

Changes:

  • Add error context to controller.New() failures
  • Add error context to Watch() setup failures for all resource types
  • Add error context to webhook controller initialization

Add error wrapping with context to controller initialization errors
to improve debugging of startup failures. This helps operators quickly
identify which controller failed during initialization without grepping
through code.

Changes:
- Add error context to controller.New() failures
- Add error context to Watch() setup failures for all resource types
- Add error context to webhook controller initialization

This follows best practices from kubernetes/kubernetes and other CNCF
projects which wrap startup errors but not runtime reconciliation errors
(which are already logged with context by defer statements).

Signed-off-by: Kunal1522 <kunalkashyap8024@gmail.com>
Copilot AI review requested due to automatic review settings January 25, 2026 13:44
@kruise-bot
Copy link

[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 fei-guo for approval by writing /assign @fei-guo 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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances error messages during controller and webhook initialization to include controller-specific context, making startup failures easier to diagnose.

Changes:

  • Wrap webhookcontroller.New initialization errors in pkg/webhook/server.go with contextual fmt.Errorf("failed to create webhook controller: %w", err).
  • Wrap controller.New and Watch setup failures in pkg/controller/cloneset/cloneset_controller.go with descriptive, controller- and resource-specific error messages.
  • Wrap controller.New and selected Watch setup failures in pkg/controller/resourcedistribution/resourcedistribution_controller.go with more informative error messages.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/webhook/server.go Adds contextual wrapping around webhook controller creation errors to clarify which component failed at startup.
pkg/controller/resourcedistribution/resourcedistribution_controller.go Adds contextual error wrapping for controller creation and some watch registrations to improve diagnostics for ResourceDistribution startup failures.
pkg/controller/cloneset/cloneset_controller.go Adds contextual error messages for CloneSet controller creation and all relevant watch registrations, aligning startup errors with the requested format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +87 to 88
return fmt.Errorf("failed to create resourcedistribution controller: %w", err)
}
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

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

The PR description and linked issue state that Watch() setup failures should be wrapped with controller-specific context for all resource types, but in this controller only the Secret and ConfigMap watches now add context while the ResourceDistribution and Namespace watches above still return the bare err. This leaves some startup failures for this controller still emitting generic errors, which partially defeats the goal of making it obvious which watch failed; consider wrapping the earlier c.Watch error returns in this function with contextual fmt.Errorf("...: %w", err) messages as well.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.67%. Comparing base (3d2cede) to head (0d3dc86).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...rcedistribution/resourcedistribution_controller.go 0.00% 5 Missing ⚠️
pkg/controller/cloneset/cloneset_controller.go 0.00% 4 Missing ⚠️
pkg/webhook/server.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2341      +/-   ##
==========================================
- Coverage   48.72%   48.67%   -0.06%     
==========================================
  Files         324      324              
  Lines       27920    27920              
==========================================
- Hits        13604    13590      -14     
- Misses      12779    12791      +12     
- Partials     1537     1539       +2     
Flag Coverage Δ
unittests 48.67% <0.00%> (-0.06%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

Address Copilot review comment: wrap ResourceDistribution and
Namespace watch errors with context messages for better debugging.

Signed-off-by: Kunal1522 <kunalkashyap8024@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S size/S 10-29

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Controller startup failures show generic errors without identifying which controller failed:

3 participants