Skip to content

✨ Reformat error wrapping for resolved bundle status #1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

trgeiger
Copy link
Contributor

Adds another test case to helm_test.go for when PreAuthorize() returns missing RBAC rules.

Description

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@trgeiger trgeiger requested a review from a team as a code owner April 25, 2025 15:36
Copy link

netlify bot commented Apr 25, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 0f0c9c4
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/680bbf296fd0080007c2f5c5
😎 Deploy Preview https://deploy-preview-1938--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 182 to 184
errMissingRBAC = "pre-authorization failed: service account requires the following permissions to manage cluster extension:\n" +
" Namespace:\"\" APIGroups:[] Resources:[services] Verbs:[list,watch]\n" +
" Namespace:\"test-namespace\" APIGroups:[*] Resources:[certificates] Verbs:[create]\n"
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest using backticks to format multi-line strings and/or strings containing quotation marks:

Suggested change
errMissingRBAC = "pre-authorization failed: service account requires the following permissions to manage cluster extension:\n" +
" Namespace:\"\" APIGroups:[] Resources:[services] Verbs:[list,watch]\n" +
" Namespace:\"test-namespace\" APIGroups:[*] Resources:[certificates] Verbs:[create]\n"
errMissingRBAC = `pre-authorization failed: service account requires the following permissions to manage cluster extension:
Namespace:"" APIGroups:[] Resources:[services] Verbs:[list,watch]
Namespace:"test-namespace" APIGroups:[*] Resources:[certificates] Verbs:[create]
`

Copy link

codecov bot commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.23%. Comparing base (a7ab445) to head (0f0c9c4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1938      +/-   ##
==========================================
+ Coverage   65.87%   66.23%   +0.35%     
==========================================
  Files          71       71              
  Lines        6189     6189              
==========================================
+ Hits         4077     4099      +22     
+ Misses       1850     1827      -23     
- Partials      262      263       +1     
Flag Coverage Δ
e2e 45.18% <100.00%> (+0.06%) ⬆️
unit 55.66% <100.00%> (+0.35%) ⬆️

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.

Comment on lines 112 to 113
// End the error in a newline since this is a heavily formatted collection of errors such as missing RBAC rules
// and we don't want it to run along into any following errors, i.e. the status error wrapping in clusterextension_controller
Copy link
Member

Choose a reason for hiding this comment

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

Is there an example of where this actually happens? If so, that's probably because we are not using errors.Join in that location?

(i.e. if we used errors.Join all the way up the stack, we'd get newlines between all the errors, but no extraneous newlines otherwise)

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I found this: https://github.com/trgeiger/operator-controller/blob/6f6737d0b7c6c9651e9f85c470a3960b760324dc/internal/operator-controller/controllers/clusterextension_controller.go#L441-L443

That will put our error message at the beginning of the string, and I could see how that could make formatting look strange. Maybe we should reformat that string so that the error still ends up at the end. Would that resolve the problem you are seeing with the lack of a trailing new line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's the specific location where this is happening. If it's fine to rework this, then I'll do that instead and make it use Join().

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's do that instead. But in this case it isn't a different error. This is just adding some context to this error. I think we should try to just rewrite the wrapping such that it is <context>: <underlying error>

Adds another test case to helm_test.go for when PreAuthorize() returns
missing RBAC rules.

Merges the noOpPreauthorizer and errPreAuthorizer into one
mockPreAuthorizer in helm_test.go.

Reverses the structure of the error string in
wrapErrorWithResolutionInfo such that the context is first and the error
follows.

Signed-off-by: Tayler Geiger <[email protected]>
@trgeiger trgeiger changed the title ✨ RBAC preflight: add newline after preauth error ✨ Reformat error wrapping for resolved bundle status Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants