-
Notifications
You must be signed in to change notification settings - Fork 71
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
fix: Function "runPromote" is overly complex #1343
base: main
Are you sure you want to change the base?
Conversation
The committers listed above are authorized under a signed CLA. |
Welcome @varshith257! |
Hi @varshith257. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ok-to-test
/ok-to-test |
@saschagrunert PTAL |
@varshith257 i would like to run that, but I need more time |
@cpanato YES! As described in the issue to make it code reusability and reduce the cognitive load of it to understand, I have split it into smaller helper functions of runPromote |
@cpanato Can you have a look into it? |
i am on PTO will be back end of august only |
I'll do the initial review in the upcoming days |
Thanks @xmudrii ! A quick info, It has been cancelled in Term 2. I am one of the applicant for this project in Term 2 and eagerly waiting to mentor under the Kubernetes organisation |
@varshith257 As far as I know, we don't have plans for submitting a project for the LFX Term 3, but follow our |
@xmudrii I am unable to join the Kubernetes slack. It's showing I don't have an email account for the workspace. Can I get an invite Link for the Kubernetes slack to join? Mail id: [email protected] |
@varshith257 Please use slack.k8s.io to register on the Kubernetes Slack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank your for this PR and the initiative to improve our code base! However, in order for this PR to get merged, the refactored code must match the original behavior prior to the refactor. I left some comments in places where this is not the case, once this is fixed, we can merge this PR. I also left some comments pointing what you can improve in this PR.
return nil | ||
} | ||
|
||
func prepareRepository(branchname string, opts *promoteOptions) (*git.Repo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits:
- given this is about the fork, maybe we should call it
prepareFork
- I have mixed feelings about
branchname
, I'd preferbranchName
, although I see that the variable inrumPromote
is calledbranchname
return nil | ||
} | ||
|
||
func prepareRepository(branchname string, opts *promoteOptions) (*git.Repo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, I'd make all these functions that take promoteOptions
as an argument, take promoteOptions
as a receiver, e.g. func (opts *promoteOptions) prepareRepository (branchname string)
@@ -232,78 +267,82 @@ func runPromote(opts *promoteOptions) error { | |||
) | |||
|
|||
// Read the current manifest to check later if new images come up | |||
oldlist := make([]byte, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code is in the mustRun
block only up to this point. I believe this function should do the same.
// add the modified manifest to staging | ||
logrus.Debugf("Adding %s to staging area", imagesListPath) | ||
if err := repo.Add(imagesListPath); err != nil { | ||
return false, fmt.Errorf("adding image manifest to staging area: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, this doesn't really feel like part of this function to me. Additionally, if you would put it in the runPronmote
function, you could avoid passing repo
and instead pass the value of repo.Dir()
.
}() | ||
|
||
// Handle manifests | ||
modified, err := handleManifests(ctx, repo, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleManifests
is a bit broad name, what do you think about calling it growManifest
instead?
if mustRun(opts, fmt.Sprintf("Push changes to user's fork at %s/%s?", opts.userFork, k8sioRepo)) { | ||
logrus.Infof("Pushing manifest changes to %s/%s", opts.userFork, k8sioRepo) | ||
if err := repo.PushToRemote(github.UserForkName, branchname); err != nil { | ||
return fmt.Errorf("pushing %s to %s/%s: %w", github.UserForkName, userForkOrg, userForkRepo, err) | ||
return fmt.Errorf("pushing %s to %s/%s: %w", github.UserForkName, opts.userFork, k8sioRepo, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong to me, why did you replace userForkOrg
with opts.userFork
and userForkRepo
with k8sioRepo
?
logrus.Infof("Exiting without creating a PR since changes were not pushed to %s/%s", opts.userFork, k8sioRepo) | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tool is supposed to exit here, however, it would continue running after this function. You should do something similar as in handleManifests
or use os.Exit
.
gh := github.New() | ||
pr, err := gh.CreatePullRequest( | ||
git.DefaultGithubOrg, k8sioRepo, k8sioDefaultBranch, | ||
fmt.Sprintf("%s:%s", opts.userFork, branchname), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you replace userForkOrg
with opts.userFork
?
pr, err := gh.CreatePullRequest( | ||
git.DefaultGithubOrg, k8sioRepo, k8sioDefaultBranch, | ||
fmt.Sprintf("%s:%s", opts.userFork, branchname), | ||
"Image promotion for "+opts.project+" "+strings.Join(opts.tags, " / "), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't match the original behavior, the commit message can be extended in some case, e.g. with the releng:
prefix.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: varshith257 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
PR needs rebase. 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. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
The current runPromote function is too complex. Instead organised code into helper functions of runPromote function
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?