Skip to content
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

Refactor secret generator controller #1311

Conversation

lburgazzoli
Copy link
Contributor

@lburgazzoli lburgazzoli commented Oct 22, 2024

Description

The PR is meant to:

  • make the code easier to understand, reducing complexity caused by nested if/else and error conditions (align happy path to the left)
  • remove shadowed error vars to avoid reporting misleading errors
  • add some basic unit test for the reconcile loop

How Has This Been Tested?

  • This does not change the behavior, the default test suite should not be affected.
  • Additional unit test case have been added

Screenshot or short clip

Merge criteria

  • You have read the contributors guide.
  • Commit messages are meaningful - have a clear and concise summary and detailed explanation of what was changed and why.
  • Pull Request contains a description of the solution, a link to the JIRA issue, and to any dependent or related Pull Request.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@ykaliuta
Copy link
Contributor

ykaliuta commented Oct 22, 2024

So, you combined 2 changes in the patch: 1) combined err and IsNotFound checks in one condition; 2) changed the Get error variable name.
Due to presents of the first one the diff is unreviewable basically due to change in the indentation level (I had to open both sources separately). It is unrelated unexpected change, draws attention of the intended change, and it is not mentioned in the commit message at all. Hint: if you negate the condition and do early return, you will save one more indentation level. UPD: and it also fixes the original problem.

The second one is the case Bartosz likes to struggle :) But it is also solvable introducing if scope only variable. Matter of taste. Of course, there would be probably no such problem, if the logic was in a separate function.

@lburgazzoli
Copy link
Contributor Author

The second one is the case Bartosz likes to struggle :) But it is also solvable introducing if scope only variable. Matter of taste. Of course, there would be probably no such problem, if the logic was in a separate function.

Yep, I made this as a draft as I'm still improving it a bit after finding I didn't like it much

@lburgazzoli lburgazzoli changed the title fix: use a different error name to avoid reporting a misleading error Refactor secret generator controller Oct 22, 2024
Copy link

codecov bot commented Oct 22, 2024

Codecov Report

Attention: Patch coverage is 56.60377% with 23 lines in your changes missing coverage. Please review.

Please upload report for BASE (incubation@b91bd29). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...lers/secretgenerator/secretgenerator_controller.go 56.60% 21 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             incubation    #1311   +/-   ##
=============================================
  Coverage              ?   18.72%           
=============================================
  Files                 ?       30           
  Lines                 ?     3364           
  Branches              ?        0           
=============================================
  Hits                  ?      630           
  Misses                ?     2668           
  Partials              ?       66           

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

@lburgazzoli lburgazzoli marked this pull request as ready for review October 22, 2024 08:05
@openshift-ci openshift-ci bot requested a review from biswassri October 22, 2024 08:05
@lburgazzoli lburgazzoli force-pushed the secret-generation-err branch 2 times, most recently from 2ac9a59 to 45a5ee6 Compare October 22, 2024 08:55
@zdtsw
Copy link
Member

zdtsw commented Oct 22, 2024

small comments (cannot do in code....)

The commit is meant to:
- make the code easier to understand, reducing complexity caused by
  nested if/else and error conditions (align happy path to the left)
- remove shadowed error vars to avoid reporting misleading errors
- add some basic unit test for the reconcile loop
@lburgazzoli
Copy link
Contributor Author

lburgazzoli commented Oct 22, 2024

@zdtsw

@ykaliuta
Copy link
Contributor

looks good to me, will leave to @zdtsw due to the conversation.

@zdtsw zdtsw mentioned this pull request Oct 22, 2024
5 tasks
Copy link

openshift-ci bot commented Oct 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zdtsw

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

The pull request process is described here

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

@openshift-merge-bot openshift-merge-bot bot merged commit a0860f4 into opendatahub-io:incubation Oct 22, 2024
10 checks passed
@lburgazzoli lburgazzoli deleted the secret-generation-err branch October 22, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants