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

Merged
merged 1 commit into from
Apr 28, 2025

Conversation

trgeiger
Copy link
Contributor

@trgeiger trgeiger commented Apr 25, 2025

Fix #1923

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 15dc223
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/680fac2b63a8660008be487d
😎 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.66%. Comparing base (1e40c87) to head (15dc223).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1938      +/-   ##
==========================================
+ Coverage   66.32%   66.66%   +0.33%     
==========================================
  Files          75       75              
  Lines        6326     6326              
==========================================
+ Hits         4196     4217      +21     
+ Misses       1866     1844      -22     
- Partials      264      265       +1     
Flag Coverage Δ
e2e 45.12% <100.00%> (ø)
unit 56.24% <100.00%> (+0.33%) ⬆️

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>

@trgeiger trgeiger changed the title ✨ RBAC preflight: add newline after preauth error ✨ Reformat error wrapping for resolved bundle status Apr 25, 2025
@kuiwang02
Copy link

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 27, 2025
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]>
Copy link

openshift-ci bot commented Apr 28, 2025

New changes are detected. LGTM label has been removed.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2025
@perdasilva perdasilva enabled auto-merge April 28, 2025 16:26
@perdasilva perdasilva added this pull request to the merge queue Apr 28, 2025
Merged via the queue into operator-framework:main with commit 1171691 Apr 28, 2025
20 checks passed
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.

Add test cases for testing RBAC preauthorization
4 participants