-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Support minSuccess #1384
Support minSuccess #1384
Changes from 5 commits
e20544d
497809d
4466570
e6b3e05
9c7c847
67e8961
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,11 @@ type JobSpec struct { | |
// If specified, indicates the job's priority. | ||
// +optional | ||
PriorityClassName string `json:"priorityClassName,omitempty" protobuf:"bytes,10,opt,name=priorityClassName"` | ||
|
||
// The minimal success pods to run for this Job | ||
// +kubebuilder:validation:Minimum=1 | ||
// +optional | ||
MinSuccess *int32 `json:"minSuccess,omitempty" protobuf:"varint,11,opt,name=minSuccess"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why set this field as *int , not int? |
||
} | ||
|
||
// VolumeSpec defines the specification of Volume, e.g. PVC. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,8 +56,17 @@ func (ps *runningState) Execute(action v1alpha1.Action) error { | |
// when scale down to zero, keep the current job phase | ||
return false | ||
} | ||
|
||
minSuccess := ps.job.Job.Spec.MinSuccess | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got the reason why you set it as *int instead of int. I perfer to int and set default value to relicas. That may be better. How do you think about it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think this field should be *int.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it's reasonable. |
||
if minSuccess != nil && status.Succeeded >= *minSuccess { | ||
status.State.Phase = vcbatch.Completed | ||
return true | ||
} | ||
|
||
if status.Succeeded+status.Failed == jobReplicas { | ||
if status.Succeeded >= ps.job.Job.Spec.MinAvailable { | ||
if minSuccess != nil && status.Succeeded < *minSuccess { | ||
status.State.Phase = vcbatch.Failed | ||
} else if status.Succeeded >= ps.job.Job.Spec.MinAvailable { | ||
status.State.Phase = vcbatch.Completed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, l agree. So maybe we can add another layer of logic inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l mean if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree |
||
} else { | ||
status.State.Phase = vcbatch.Failed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2021 The Volcano Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package jobp | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
vcbatch "volcano.sh/volcano/pkg/apis/batch/v1alpha1" | ||
|
||
e2eutil "volcano.sh/volcano/test/e2e/util" | ||
) | ||
|
||
var _ = Describe("Check min success", func() { | ||
It("Min Success", func() { | ||
By("init test ctx") | ||
ctx := e2eutil.InitTestContext(e2eutil.Options{}) | ||
defer e2eutil.CleanupTestContext(ctx) | ||
|
||
jobName := "min-success-job" | ||
By("create job") | ||
var minSuccess int32 = 2 | ||
job := e2eutil.CreateJob(ctx, &e2eutil.JobSpec{ | ||
Name: jobName, | ||
MinSuccess: &minSuccess, | ||
Tasks: []e2eutil.TaskSpec{ | ||
{ | ||
Name: "short", | ||
Img: e2eutil.DefaultBusyBoxImage, | ||
Min: 1, | ||
Rep: 3, | ||
Command: "sleep 3", | ||
}, | ||
{ | ||
Name: "log", | ||
Img: e2eutil.DefaultBusyBoxImage, | ||
Min: 1, | ||
Rep: 2, | ||
Command: "sleep 100000", | ||
}, | ||
}, | ||
}) | ||
|
||
// job phase: pending -> running | ||
err := e2eutil.WaitJobReady(ctx, job) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// wait short tasks completed | ||
err = e2eutil.WaitTasksCompleted(ctx, job, minSuccess) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// wait job completed | ||
err = e2eutil.WaitJobStates(ctx, job, []vcbatch.JobPhase{vcbatch.Completed}, e2eutil.OneMinute) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) |
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.
It's better to set the replicas as the default value.