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

Code cleanup and refactoring #484

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

danielvegamyhre
Copy link
Contributor

@danielvegamyhre danielvegamyhre commented Mar 28, 2024

Code cleanup and refactoring

  • Move more event reasons and messages into constants package
  • Refactor suspendJobSet to suspendJobs to follow same pattern as createJobs and deleteJobs, as well as improve readability (since before the logic read "if jobset is suspended, suspend jobset"
  • Refactor resumeJobsIfNecessary similarly to above
  • Split "generateStartupPolicyCondition(metav1.True or metav1.False)" into two functions for readability, which better indicate the possible conditions and their semantic meaning:
    • inOrderStartupPolicyExecutingCondition()
    • inOrderStartupPolicyCompletedCondition
  • Add some comments throughout the code base where I think things could some explanation
  • Rename rjobStarted to allReplicasStarted to better indicate what exactly is required for a replicatedJob to be considered started.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danielvegamyhre

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 28, 2024
@k8s-ci-robot k8s-ci-robot requested review from ahg-g and kannon92 March 28, 2024 05:26
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 28, 2024
Copy link

netlify bot commented Mar 28, 2024

Deploy Preview for kubernetes-sigs-jobset canceled.

Name Link
🔨 Latest commit 395459b
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-jobset/deploys/6604ff791c78180008e67a10

if inOrderStartupPolicy(startupPolicy) {
return r.ensureCondition(ctx, ensureConditionOpts{
if err := r.ensureCondition(ctx, ensureConditionOpts{
Copy link
Contributor

@kannon92 kannon92 Mar 28, 2024

Choose a reason for hiding this comment

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

This is changing the behavior.

We want to return here if startup policy is being applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sorry I forgot to put a note here explaining this change. My thought was this was a bug that we are returning early here, because otherwise we never set the condition below that indicates the JobSet has been resumed; we only add the condition that startup policy is done. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did that by design.

I return the jobset to trigger a reconcile. I only want to resume the jobset once all the jobs have resumed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why I return is that I don't want to go to the next job in the loop until the previous job is started.

I think this could potentially start the next job once the previously is resumed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why I return is that I don't want to go to the next job in the loop until the previous job is started.

This is outside the loop though. Inside the loop we still do the early return on line 361, to wait for the replicatedJob we just resumed to be ready before moving on to the next.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha. Yea I guess that is so..

Copy link
Contributor

@kannon92 kannon92 Mar 28, 2024

Choose a reason for hiding this comment

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

imo I would really try to keep bug fixes separate from refactor PRs. It makes backports and such much more difficult..

/hold

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move this fix into a separate PR?

@kannon92
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 28, 2024
@danielvegamyhre
Copy link
Contributor Author

Thanks for the quick review @kannon92 ! We can go ahead and merge since this is just refactoring and a minor bug fix. I will keep bug fixes separate from refactors going forward as you mentioned

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 28, 2024
@k8s-ci-robot k8s-ci-robot merged commit f7d8038 into kubernetes-sigs:main Mar 28, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants