-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add restart strategy #686
Add restart strategy #686
Conversation
Welcome @nstogner! |
Hi @nstogner. 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. |
✅ Deploy Preview for kubernetes-sigs-jobset ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
/ok-to-test |
// RestartStrategy defines the strategy to use when restarting the JobSet. | ||
// Defaults to Recreate. | ||
// +optional | ||
// +kubebuilder:default=Recreate |
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.
Can we do validation here as follows:
// +kubebuilder:validation:Enum:=
Also, if the user was running a jobset and at the same time upgraded the controller, I suspect that this field will not exist for this job. I think this needs to be a reference that we explicitly default in the webhook and in the controller code (default the field if not set) to ensure we don't break running jobsets.
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.
Added the enum validation. Here is the behavior as-is when the CRD is updated (default is applied when JobSet is read after update of CRD):
(base) ➜ jobset.blocking-recreate git:(restart-strategy) kind create cluster
using podman due to KIND_EXPERIMENTAL_PROVIDER
enabling experimental podman provider
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.29.2) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Have a nice day! 👋
(base) ➜ jobset.blocking-recreate git:(restart-strategy) git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
(base) ➜ jobset.blocking-recreate git:(main) kubectl apply --server-side -k ./config/components/crd
# Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
customresourcedefinition.apiextensions.k8s.io/jobsets.jobset.x-k8s.io serverside-applied
(base) ➜ jobset.blocking-recreate git:(main) kubectl apply -f ./examples/simple/max-restarts.yaml
jobset.jobset.x-k8s.io/max-restarts created
(base) ➜ jobset.blocking-recreate git:(main) kubectl get jobsets -oyaml | grep -A 3 failurePolicy
failurePolicy:
maxRestarts: 3
replicatedJobs:
- name: leader
(base) ➜ jobset.blocking-recreate git:(main) git checkout -
Switched to branch 'restart-strategy'
Your branch is up to date with 'nstogner/restart-strategy'.
(base) ➜ jobset.blocking-recreate git:(restart-strategy) kubectl apply --server-side -k ./config/components/crd
# Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
customresourcedefinition.apiextensions.k8s.io/jobsets.jobset.x-k8s.io serverside-applied
(base) ➜ jobset.blocking-recreate git:(restart-strategy) kubectl get jobsets -oyaml | grep -A 3 failurePolicy
failurePolicy:
maxRestarts: 3
restartStrategy: Recreate # <----- Default is applied
replicatedJobs:
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.
Seems like this will not break existing JobSets... WDYT?
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.
sg, can you add the validation, it is not on the last commit.
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.
oh, I see you added it on the enum definition itself, make sense
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.
Looks like a useful change, the idea is to resolve the issue described here correct?
Added a few comments.
pkg/controllers/jobset_controller.go
Outdated
// If the JobSet is using the BlockingRecreate failure policy, we should not create any new jobs until | ||
// all the jobs slated for deletion (i.e. from the last restart index) have been deleted. | ||
if len(ownedJobs.previous) > 0 && | ||
js.Spec.FailurePolicy != nil && js.Spec.FailurePolicy.RestartStrategy == jobset.BlockingRecreate { |
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.
nit: can we store js.Spec.FailurePolicy != nil && js.Spec.FailurePolicy.RestartStrategy == jobset.BlockingRecreate
in a variable to make this big if-statement more concise and readable?
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.
Updated
}, | ||
}, | ||
}), | ||
// TODO(nstogner): Add test case for BlockingRecreate!!! |
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.
We should add this test case for blockingRecreate before merging
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.
Done
{ | ||
checkJobSetState: func(js *jobset.JobSet) { | ||
ginkgo.By("checking 3/4 jobs were recreated") | ||
exp := map[int]int{ |
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.
Can we rename exp
to something a little more descriptive which makes it clear what the keys and values represent, so people reading the code don't need to reverse-engineer it by finding where/how it's used, etc.
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.
Updated
Yep, thats exactly what this is targeting. |
61d63ee
to
55c8787
Compare
@nstogner you probably need to run |
/lgtm Great, thanks! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, nstogner 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #684
Special notes for your reviewer:
Does this PR introduce a user-facing change?