Skip to content

✨ Reformat error wrapping for resolved bundle status - #1938

Merged
perdasilva merged 1 commit into
operator-framework:mainfrom
trgeiger:rbac-errors-2
Apr 28, 2025
Merged

✨ Reformat error wrapping for resolved bundle status#1938
perdasilva merged 1 commit into
operator-framework:mainfrom
trgeiger:rbac-errors-2

Conversation

@trgeiger

@trgeigertrgeiger commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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 ownerApril 25, 2025 15:36
@netlify

netlifyBot commented Apr 25, 2025

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

NameLink
🔨 Latest commit15dc223
🔍 Latest deploy loghttps://app.netlify.com/sites/olmv1/deploys/680fac2b63a8660008be487d
😎 Deploy Previewhttps://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
Copy Markdown
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]
`

@codecov

codecovBot commented Apr 25, 2025

Copy link
Copy Markdown

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 
FlagCoverage Δ
e2e45.12% <100.00%> (ø)
unit56.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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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>

@trgeigertrgeiger changed the title ✨ RBAC preflight: add newline after preauth error✨ Reformat error wrapping for resolved bundle statusApr 25, 2025
@kuiwang02

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ciopenshift-ciBot 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 <tayler@redhat.com>
@openshift-ci

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@openshift-ciopenshift-ciBot 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 1171691Apr 28, 2025
Sign up for freeto 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

@trgeiger@kuiwang02@joelanford@perdasilva