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

chore: remove duplicated logic by function call #1080

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

zdtsw
Copy link
Member

@zdtsw zdtsw commented Jun 25, 2024

Description

ref: https://issues.redhat.com/browse/RHOAIENG-8995

How Has This Been Tested?

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

@openshift-ci openshift-ci bot requested review from etirelli and Sara4994 June 25, 2024 13:35
@zdtsw zdtsw requested review from ykaliuta and VaishnaviHire and removed request for etirelli and Sara4994 June 25, 2024 14:35
@ykaliuta
Copy link
Contributor

So, what do you think about #1077 (comment) or I'm missing something?

@zdtsw
Copy link
Member Author

zdtsw commented Jun 25, 2024

So, what do you think about #1077 (comment) or I'm missing something?

i did not see that one. i will give it a think tomorrow.

func generateCertSecret(ctx context.Context, c client.Client, certSecret *corev1.Secret, secretName, namespace string) error {
existingSecret := &corev1.Secret{}
err := c.Get(ctx, client.ObjectKey{Name: secretName, Namespace: namespace}, existingSecret)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this chain of if if if else elseif if a bit more confusing than the proposal, but fine for me if it's better for you, clear enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

My way of thinking behind using switch is that we have 3 cases for Get: existing object, non-existing object, error of fetching. Not 2 as for if-else.

Copy link
Member Author

Choose a reason for hiding this comment

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

i was not very fond of using switch in this case, thats why tried to avoid it.
but after reading Luca's comments, maybe switch is much better for a quick return.
let me do some updates again

return errors.New("failed to recreate secret with type corrected")
}
}
if isSecretOutdated(existingSecret.Data, certSecret.Data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, in the original code it was part of only one function, just kept the functionality as is, had a thought that it should be in both :) Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

i had the same thoughts, why at first we did not have outdated secret updated, unless some reason behind it.
Just wanna @VaishnaviHire take a look in case it should not be.

return errors.New("failed to recreate secret with type corrected")
}
}
if isSecretOutdated(existingSecret.Data, certSecret.Data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I properly understood the code, the isSecretOutdated function is invoked even if the secret is created or recreated but since the existingSecret is never updated (and there is no reason to do it), then it could lead to a spurious Update so the two if/else should probably return early.

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right.

  • in the successful Create() case, it should return immediately
  • in the recreateSecret() case, it does not need to check isSecretOutdated() as well

- change if-else-if to switch
- fast return in recreateSecret case

Signed-off-by: Wen Zhou <[email protected]>
@ykaliuta
Copy link
Contributor

Fine for me. I'll wait for @lburgazzoli final word to avoid automatic merging.

@zdtsw
Copy link
Member Author

zdtsw commented Jun 26, 2024

Fine for me. I'll wait for @lburgazzoli final word to avoid automatic merging.

put on a "hold" label, we are safe now 😢 + 😆

Copy link

openshift-ci bot commented Jun 26, 2024

@lburgazzoli: changing LGTM is restricted to collaborators

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

openshift-ci bot commented Jun 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lburgazzoli, ykaliuta

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

@zdtsw zdtsw merged commit f3e6a13 into opendatahub-io:incubation Jun 26, 2024
7 of 8 checks passed
zdtsw added a commit to zdtsw-forking/rhods-operator that referenced this pull request Jun 26, 2024
* chore: remove duplicated logic by function call
- change if-else-if to switch
- fast return in recreateSecret case

---------
Signed-off-by: Wen Zhou <[email protected]>
openshift-merge-bot bot pushed a commit to red-hat-data-services/rhods-operator that referenced this pull request Jun 26, 2024
* chore: remove duplicated logic by function call
- change if-else-if to switch
- fast return in recreateSecret case

---------
Signed-off-by: Wen Zhou <[email protected]>
zdtsw added a commit to zdtsw-forking/opendatahub-operator that referenced this pull request Jul 9, 2024
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Jul 24, 2024
* chore: remove duplicated logic by function call
- change if-else-if to switch
- fast return in recreateSecret case

---------
Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit f3e6a13)
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Jul 24, 2024
* chore: remove duplicated logic by function call
- change if-else-if to switch
- fast return in recreateSecret case

---------
Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit f3e6a13)
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