Commit 327c1044 authored by Maciej Szulik's avatar Maciej Szulik

Added ActiveDeadlineSeconds to jobs, allowing failing a job after

exceeding allowed time.
parent efc821a1
...@@ -3219,6 +3219,11 @@ ...@@ -3219,6 +3219,11 @@
"format": "int32", "format": "int32",
"description": "Completions specifies the desired number of successfully finished pods the job should be run with. Defaults to 1. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md" "description": "Completions specifies the desired number of successfully finished pods the job should be run with. Defaults to 1. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md"
}, },
"activeDeadlineSeconds": {
"type": "integer",
"format": "int64",
"description": "Optional duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer"
},
"selector": { "selector": {
"$ref": "v1beta1.LabelSelector", "$ref": "v1beta1.LabelSelector",
"description": "Selector is a label query over pods that should match the pod count. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors" "description": "Selector is a label query over pods that should match the pod count. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors"
......
...@@ -1383,6 +1383,12 @@ func deepCopy_extensions_JobSpec(in JobSpec, out *JobSpec, c *conversion.Cloner) ...@@ -1383,6 +1383,12 @@ func deepCopy_extensions_JobSpec(in JobSpec, out *JobSpec, c *conversion.Cloner)
} else { } else {
out.Completions = nil out.Completions = nil
} }
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
} else {
out.ActiveDeadlineSeconds = nil
}
if in.Selector != nil { if in.Selector != nil {
out.Selector = new(LabelSelector) out.Selector = new(LabelSelector)
if err := deepCopy_extensions_LabelSelector(*in.Selector, out.Selector, c); err != nil { if err := deepCopy_extensions_LabelSelector(*in.Selector, out.Selector, c); err != nil {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -410,6 +410,10 @@ type JobSpec struct { ...@@ -410,6 +410,10 @@ type JobSpec struct {
// job should be run with. Defaults to 1. // job should be run with. Defaults to 1.
Completions *int `json:"completions,omitempty"` Completions *int `json:"completions,omitempty"`
// Optional duration in seconds relative to the startTime that the job may be active
// before the system tries to terminate it; value must be positive integer
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty"`
// Selector is a label query over pods that should match the pod count. // Selector is a label query over pods that should match the pod count.
Selector *LabelSelector `json:"selector,omitempty"` Selector *LabelSelector `json:"selector,omitempty"`
...@@ -450,6 +454,8 @@ type JobConditionType string ...@@ -450,6 +454,8 @@ type JobConditionType string
const ( const (
// JobComplete means the job has completed its execution. // JobComplete means the job has completed its execution.
JobComplete JobConditionType = "Complete" JobComplete JobConditionType = "Complete"
// JobFailed means the job has failed its execution.
JobFailed JobConditionType = "Failed"
) )
// JobCondition describes current state of a job. // JobCondition describes current state of a job.
......
...@@ -2902,6 +2902,12 @@ func autoconvert_extensions_JobSpec_To_v1beta1_JobSpec(in *extensions.JobSpec, o ...@@ -2902,6 +2902,12 @@ func autoconvert_extensions_JobSpec_To_v1beta1_JobSpec(in *extensions.JobSpec, o
} else { } else {
out.Completions = nil out.Completions = nil
} }
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
} else {
out.ActiveDeadlineSeconds = nil
}
if in.Selector != nil { if in.Selector != nil {
out.Selector = new(LabelSelector) out.Selector = new(LabelSelector)
if err := convert_extensions_LabelSelector_To_v1beta1_LabelSelector(in.Selector, out.Selector, s); err != nil { if err := convert_extensions_LabelSelector_To_v1beta1_LabelSelector(in.Selector, out.Selector, s); err != nil {
...@@ -3921,6 +3927,12 @@ func autoconvert_v1beta1_JobSpec_To_extensions_JobSpec(in *JobSpec, out *extensi ...@@ -3921,6 +3927,12 @@ func autoconvert_v1beta1_JobSpec_To_extensions_JobSpec(in *JobSpec, out *extensi
} else { } else {
out.Completions = nil out.Completions = nil
} }
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
} else {
out.ActiveDeadlineSeconds = nil
}
if in.Selector != nil { if in.Selector != nil {
out.Selector = new(extensions.LabelSelector) out.Selector = new(extensions.LabelSelector)
if err := convert_v1beta1_LabelSelector_To_extensions_LabelSelector(in.Selector, out.Selector, s); err != nil { if err := convert_v1beta1_LabelSelector_To_extensions_LabelSelector(in.Selector, out.Selector, s); err != nil {
......
...@@ -1395,6 +1395,12 @@ func deepCopy_v1beta1_JobSpec(in JobSpec, out *JobSpec, c *conversion.Cloner) er ...@@ -1395,6 +1395,12 @@ func deepCopy_v1beta1_JobSpec(in JobSpec, out *JobSpec, c *conversion.Cloner) er
} else { } else {
out.Completions = nil out.Completions = nil
} }
if in.ActiveDeadlineSeconds != nil {
out.ActiveDeadlineSeconds = new(int64)
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
} else {
out.ActiveDeadlineSeconds = nil
}
if in.Selector != nil { if in.Selector != nil {
out.Selector = new(LabelSelector) out.Selector = new(LabelSelector)
if err := deepCopy_v1beta1_LabelSelector(*in.Selector, out.Selector, c); err != nil { if err := deepCopy_v1beta1_LabelSelector(*in.Selector, out.Selector, c); err != nil {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -415,6 +415,10 @@ type JobSpec struct { ...@@ -415,6 +415,10 @@ type JobSpec struct {
// More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md // More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md
Completions *int32 `json:"completions,omitempty"` Completions *int32 `json:"completions,omitempty"`
// Optional duration in seconds relative to the startTime that the job may be active
// before the system tries to terminate it; value must be positive integer
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty"`
// Selector is a label query over pods that should match the pod count. // Selector is a label query over pods that should match the pod count.
// More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors // More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors
Selector *LabelSelector `json:"selector,omitempty"` Selector *LabelSelector `json:"selector,omitempty"`
...@@ -458,6 +462,8 @@ type JobConditionType string ...@@ -458,6 +462,8 @@ type JobConditionType string
const ( const (
// JobComplete means the job has completed its execution. // JobComplete means the job has completed its execution.
JobComplete JobConditionType = "Complete" JobComplete JobConditionType = "Complete"
// JobFailed means the job has failed its execution.
JobFailed JobConditionType = "Failed"
) )
// JobCondition describes current state of a job. // JobCondition describes current state of a job.
......
...@@ -368,11 +368,12 @@ func (JobList) SwaggerDoc() map[string]string { ...@@ -368,11 +368,12 @@ func (JobList) SwaggerDoc() map[string]string {
} }
var map_JobSpec = map[string]string{ var map_JobSpec = map[string]string{
"": "JobSpec describes how the job execution will look like.", "": "JobSpec describes how the job execution will look like.",
"parallelism": "Parallelism specifies the maximum desired number of pods the job should run at any given time. The actual number of pods running in steady state will be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism), i.e. when the work left to do is less than max parallelism. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md", "parallelism": "Parallelism specifies the maximum desired number of pods the job should run at any given time. The actual number of pods running in steady state will be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism), i.e. when the work left to do is less than max parallelism. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md",
"completions": "Completions specifies the desired number of successfully finished pods the job should be run with. Defaults to 1. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md", "completions": "Completions specifies the desired number of successfully finished pods the job should be run with. Defaults to 1. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md",
"selector": "Selector is a label query over pods that should match the pod count. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors", "activeDeadlineSeconds": "Optional duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer",
"template": "Template is the object that describes the pod that will be created when executing a job. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md", "selector": "Selector is a label query over pods that should match the pod count. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors",
"template": "Template is the object that describes the pod that will be created when executing a job. More info: http://releases.k8s.io/HEAD/docs/user-guide/jobs.md",
} }
func (JobSpec) SwaggerDoc() map[string]string { func (JobSpec) SwaggerDoc() map[string]string {
......
...@@ -338,6 +338,9 @@ func ValidateJobSpec(spec *extensions.JobSpec, fldPath *field.Path) field.ErrorL ...@@ -338,6 +338,9 @@ func ValidateJobSpec(spec *extensions.JobSpec, fldPath *field.Path) field.ErrorL
if spec.Completions != nil { if spec.Completions != nil {
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(*spec.Completions), fldPath.Child("completions"))...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(*spec.Completions), fldPath.Child("completions"))...)
} }
if spec.ActiveDeadlineSeconds != nil {
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(*spec.ActiveDeadlineSeconds), fldPath.Child("activeDeadlineSeconds"))...)
}
if spec.Selector == nil { if spec.Selector == nil {
allErrs = append(allErrs, field.Required(fldPath.Child("selector"))) allErrs = append(allErrs, field.Required(fldPath.Child("selector")))
} else { } else {
......
...@@ -839,6 +839,7 @@ func TestValidateJob(t *testing.T) { ...@@ -839,6 +839,7 @@ func TestValidateJob(t *testing.T) {
} }
} }
negative := -1 negative := -1
negative64 := int64(-1)
errorCases := map[string]extensions.Job{ errorCases := map[string]extensions.Job{
"spec.parallelism:must be non-negative": { "spec.parallelism:must be non-negative": {
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
...@@ -862,6 +863,17 @@ func TestValidateJob(t *testing.T) { ...@@ -862,6 +863,17 @@ func TestValidateJob(t *testing.T) {
Template: validPodTemplateSpec, Template: validPodTemplateSpec,
}, },
}, },
"spec.activeDeadlineSeconds:must be non-negative": {
ObjectMeta: api.ObjectMeta{
Name: "myjob",
Namespace: api.NamespaceDefault,
},
Spec: extensions.JobSpec{
ActiveDeadlineSeconds: &negative64,
Selector: validSelector,
Template: validPodTemplateSpec,
},
},
"spec.selector:required value": { "spec.selector:required value": {
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "myjob", Name: "myjob",
......
...@@ -64,6 +64,8 @@ type JobController struct { ...@@ -64,6 +64,8 @@ type JobController struct {
// Jobs that need to be updated // Jobs that need to be updated
queue *workqueue.Type queue *workqueue.Type
recorder record.EventRecorder
} }
func NewJobController(kubeClient client.Interface, resyncPeriod controller.ResyncPeriodFunc) *JobController { func NewJobController(kubeClient client.Interface, resyncPeriod controller.ResyncPeriodFunc) *JobController {
...@@ -75,10 +77,11 @@ func NewJobController(kubeClient client.Interface, resyncPeriod controller.Resyn ...@@ -75,10 +77,11 @@ func NewJobController(kubeClient client.Interface, resyncPeriod controller.Resyn
kubeClient: kubeClient, kubeClient: kubeClient,
podControl: controller.RealPodControl{ podControl: controller.RealPodControl{
KubeClient: kubeClient, KubeClient: kubeClient,
Recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "job"}), Recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "job-controller"}),
}, },
expectations: controller.NewControllerExpectations(), expectations: controller.NewControllerExpectations(),
queue: workqueue.New(), queue: workqueue.New(),
recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "job-controller"}),
} }
jm.jobStore.Store, jm.jobController = framework.NewInformer( jm.jobStore.Store, jm.jobController = framework.NewInformer(
...@@ -322,16 +325,52 @@ func (jm *JobController) syncJob(key string) error { ...@@ -322,16 +325,52 @@ func (jm *JobController) syncJob(key string) error {
activePods := controller.FilterActivePods(podList.Items) activePods := controller.FilterActivePods(podList.Items)
active := len(activePods) active := len(activePods)
succeeded, failed := getStatus(podList.Items) succeeded, failed := getStatus(podList.Items)
if jobNeedsSync { conditions := len(job.Status.Conditions)
active = jm.manageJob(activePods, succeeded, &job) if job.Status.StartTime == nil {
now := unversioned.Now()
job.Status.StartTime = &now
} }
completions := succeeded if pastActiveDeadline(&job) {
if completions == *job.Spec.Completions { // if job was finished previously, we don't want to redo the termination
job.Status.Conditions = append(job.Status.Conditions, newCondition()) if isJobFinished(&job) {
return nil
}
// TODO: below code should be replaced with pod termination resulting in
// pod failures, rather than killing pods. Unfortunately none such solution
// exists ATM. There's an open discussion in the topic in
// https://github.com/kubernetes/kubernetes/issues/14602 which might give
// some sort of solution to above problem.
// kill remaining active pods
wait := sync.WaitGroup{}
wait.Add(active)
for i := 0; i < active; i++ {
go func(ix int) {
defer wait.Done()
if err := jm.podControl.DeletePod(job.Namespace, activePods[ix].Name); err != nil {
defer util.HandleError(err)
}
}(i)
}
wait.Wait()
// update status values accordingly
failed += active
active = 0
job.Status.Conditions = append(job.Status.Conditions, newCondition(extensions.JobFailed, "DeadlineExceeded", "Job was active longer than specified deadline"))
jm.recorder.Event(&job, api.EventTypeNormal, "DeadlineExceeded", "Job was active longer than specified deadline")
} else {
if jobNeedsSync {
active = jm.manageJob(activePods, succeeded, &job)
}
completions := succeeded
if completions == *job.Spec.Completions {
job.Status.Conditions = append(job.Status.Conditions, newCondition(extensions.JobComplete, "", ""))
now := unversioned.Now()
job.Status.CompletionTime = &now
}
} }
// no need to update the job if the status hasn't changed since last time // no need to update the job if the status hasn't changed since last time
if job.Status.Active != active || job.Status.Succeeded != succeeded || job.Status.Failed != failed { if job.Status.Active != active || job.Status.Succeeded != succeeded || job.Status.Failed != failed || len(job.Status.Conditions) != conditions {
job.Status.Active = active job.Status.Active = active
job.Status.Succeeded = succeeded job.Status.Succeeded = succeeded
job.Status.Failed = failed job.Status.Failed = failed
...@@ -344,21 +383,38 @@ func (jm *JobController) syncJob(key string) error { ...@@ -344,21 +383,38 @@ func (jm *JobController) syncJob(key string) error {
return nil return nil
} }
func newCondition() extensions.JobCondition { // pastActiveDeadline checks if job has ActiveDeadlineSeconds field set and if it is exceeded.
func pastActiveDeadline(job *extensions.Job) bool {
if job.Spec.ActiveDeadlineSeconds == nil || job.Status.StartTime == nil {
return false
}
now := unversioned.Now()
start := job.Status.StartTime.Time
duration := now.Time.Sub(start)
allowedDuration := time.Duration(*job.Spec.ActiveDeadlineSeconds) * time.Second
return duration >= allowedDuration
}
func newCondition(conditionType extensions.JobConditionType, reason, message string) extensions.JobCondition {
return extensions.JobCondition{ return extensions.JobCondition{
Type: extensions.JobComplete, Type: conditionType,
Status: api.ConditionTrue, Status: api.ConditionTrue,
LastProbeTime: unversioned.Now(), LastProbeTime: unversioned.Now(),
LastTransitionTime: unversioned.Now(), LastTransitionTime: unversioned.Now(),
Reason: reason,
Message: message,
} }
} }
// getStatus returns no of succeeded and failed pods running a job
func getStatus(pods []api.Pod) (succeeded, failed int) { func getStatus(pods []api.Pod) (succeeded, failed int) {
succeeded = filterPods(pods, api.PodSucceeded) succeeded = filterPods(pods, api.PodSucceeded)
failed = filterPods(pods, api.PodFailed) failed = filterPods(pods, api.PodFailed)
return return
} }
// manageJob is the core method responsible for managing the number of running
// pods according to what is specified in the job.Spec.
func (jm *JobController) manageJob(activePods []*api.Pod, succeeded int, job *extensions.Job) int { func (jm *JobController) manageJob(activePods []*api.Pod, succeeded int, job *extensions.Job) int {
var activeLock sync.Mutex var activeLock sync.Mutex
active := len(activePods) active := len(activePods)
...@@ -447,7 +503,7 @@ func filterPods(pods []api.Pod, phase api.PodPhase) int { ...@@ -447,7 +503,7 @@ func filterPods(pods []api.Pod, phase api.PodPhase) int {
func isJobFinished(j *extensions.Job) bool { func isJobFinished(j *extensions.Job) bool {
for _, c := range j.Status.Conditions { for _, c := range j.Status.Conditions {
if c.Type == extensions.JobComplete && c.Status == api.ConditionTrue { if (c.Type == extensions.JobComplete || c.Type == extensions.JobFailed) && c.Status == api.ConditionTrue {
return true return true
} }
} }
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient" "k8s.io/kubernetes/pkg/client/unversioned/testclient"
...@@ -209,22 +210,158 @@ func TestControllerSyncJob(t *testing.T) { ...@@ -209,22 +210,158 @@ func TestControllerSyncJob(t *testing.T) {
if actual.Status.Failed != tc.expectedFailed { if actual.Status.Failed != tc.expectedFailed {
t.Errorf("%s: unexpected number of failed pods. Expected %d, saw %d\n", name, tc.expectedFailed, actual.Status.Failed) t.Errorf("%s: unexpected number of failed pods. Expected %d, saw %d\n", name, tc.expectedFailed, actual.Status.Failed)
} }
if actual.Status.StartTime == nil {
t.Errorf("%s: .status.startTime was not set", name)
}
// validate conditions // validate conditions
if tc.expectedComplete { if tc.expectedComplete && !getCondition(actual, extensions.JobComplete) {
completed := false t.Errorf("%s: expected completion condition. Got %#v", name, actual.Status.Conditions)
for _, v := range actual.Status.Conditions { }
if v.Type == extensions.JobComplete && v.Status == api.ConditionTrue { }
completed = true }
break
} func TestSyncJobPastDeadline(t *testing.T) {
} testCases := map[string]struct {
if !completed { // job setup
t.Errorf("%s: expected completion condition. Got %v", name, actual.Status.Conditions) parallelism int
} completions int
activeDeadlineSeconds int64
startTime int64
// pod setup
activePods int
succeededPods int
failedPods int
// expectations
expectedDeletions int
expectedActive int
expectedSucceeded int
expectedFailed int
}{
"activeDeadlineSeconds less than single pod execution": {
1, 1, 10, 15,
1, 0, 0,
1, 0, 0, 1,
},
"activeDeadlineSeconds bigger than single pod execution": {
1, 2, 10, 15,
1, 1, 0,
1, 0, 1, 1,
},
"activeDeadlineSeconds times-out before any pod starts": {
1, 1, 10, 10,
0, 0, 0,
0, 0, 0, 0,
},
}
for name, tc := range testCases {
// job manager setup
client := client.NewOrDie(&client.Config{Host: "", GroupVersion: testapi.Default.GroupVersion()})
manager := NewJobController(client, controller.NoResyncPeriodFunc)
fakePodControl := controller.FakePodControl{}
manager.podControl = &fakePodControl
manager.podStoreSynced = alwaysReady
var actual *extensions.Job
manager.updateHandler = func(job *extensions.Job) error {
actual = job
return nil
}
// job & pods setup
job := newJob(tc.parallelism, tc.completions)
job.Spec.ActiveDeadlineSeconds = &tc.activeDeadlineSeconds
start := unversioned.Unix(unversioned.Now().Time.Unix()-tc.startTime, 0)
job.Status.StartTime = &start
manager.jobStore.Store.Add(job)
for _, pod := range newPodList(tc.activePods, api.PodRunning, job) {
manager.podStore.Store.Add(&pod)
}
for _, pod := range newPodList(tc.succeededPods, api.PodSucceeded, job) {
manager.podStore.Store.Add(&pod)
}
for _, pod := range newPodList(tc.failedPods, api.PodFailed, job) {
manager.podStore.Store.Add(&pod)
}
// run
err := manager.syncJob(getKey(job, t))
if err != nil {
t.Errorf("%s: unexpected error when syncing jobs %v", err)
}
// validate created/deleted pods
if len(fakePodControl.Templates) != 0 {
t.Errorf("%s: unexpected number of creates. Expected 0, saw %d\n", name, len(fakePodControl.Templates))
}
if len(fakePodControl.DeletePodName) != tc.expectedDeletions {
t.Errorf("%s: unexpected number of deletes. Expected %d, saw %d\n", name, tc.expectedDeletions, len(fakePodControl.DeletePodName))
}
// validate status
if actual.Status.Active != tc.expectedActive {
t.Errorf("%s: unexpected number of active pods. Expected %d, saw %d\n", name, tc.expectedActive, actual.Status.Active)
}
if actual.Status.Succeeded != tc.expectedSucceeded {
t.Errorf("%s: unexpected number of succeeded pods. Expected %d, saw %d\n", name, tc.expectedSucceeded, actual.Status.Succeeded)
}
if actual.Status.Failed != tc.expectedFailed {
t.Errorf("%s: unexpected number of failed pods. Expected %d, saw %d\n", name, tc.expectedFailed, actual.Status.Failed)
}
if actual.Status.StartTime == nil {
t.Errorf("%s: .status.startTime was not set", name)
}
// validate conditions
if !getCondition(actual, extensions.JobFailed) {
t.Errorf("%s: expected fail condition. Got %#v", name, actual.Status.Conditions)
} }
} }
} }
func getCondition(job *extensions.Job, condition extensions.JobConditionType) bool {
for _, v := range job.Status.Conditions {
if v.Type == condition && v.Status == api.ConditionTrue {
return true
}
}
return false
}
func TestSyncPastDeadlineJobFinished(t *testing.T) {
client := client.NewOrDie(&client.Config{Host: "", GroupVersion: testapi.Default.GroupVersion()})
manager := NewJobController(client, controller.NoResyncPeriodFunc)
fakePodControl := controller.FakePodControl{}
manager.podControl = &fakePodControl
manager.podStoreSynced = alwaysReady
var actual *extensions.Job
manager.updateHandler = func(job *extensions.Job) error {
actual = job
return nil
}
job := newJob(1, 1)
activeDeadlineSeconds := int64(10)
job.Spec.ActiveDeadlineSeconds = &activeDeadlineSeconds
start := unversioned.Unix(unversioned.Now().Time.Unix()-15, 0)
job.Status.StartTime = &start
job.Status.Conditions = append(job.Status.Conditions, newCondition(extensions.JobFailed, "DeadlineExceeded", "Job was active longer than specified deadline"))
manager.jobStore.Store.Add(job)
err := manager.syncJob(getKey(job, t))
if err != nil {
t.Errorf("Unexpected error when syncing jobs %v", err)
}
if len(fakePodControl.Templates) != 0 {
t.Errorf("Unexpected number of creates. Expected %d, saw %d\n", 0, len(fakePodControl.Templates))
}
if len(fakePodControl.DeletePodName) != 0 {
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", 0, len(fakePodControl.DeletePodName))
}
if actual != nil {
t.Error("Unexpected job modification")
}
}
func TestSyncJobDeleted(t *testing.T) { func TestSyncJobDeleted(t *testing.T) {
client := client.NewOrDie(&client.Config{Host: "", GroupVersion: testapi.Default.GroupVersion()}) client := client.NewOrDie(&client.Config{Host: "", GroupVersion: testapi.Default.GroupVersion()})
manager := NewJobController(client, controller.NoResyncPeriodFunc) manager := NewJobController(client, controller.NoResyncPeriodFunc)
......
...@@ -895,6 +895,12 @@ func describeJob(job *extensions.Job, events *api.EventList) (string, error) { ...@@ -895,6 +895,12 @@ func describeJob(job *extensions.Job, events *api.EventList) (string, error) {
fmt.Fprintf(out, "Selector:\t%s\n", selector) fmt.Fprintf(out, "Selector:\t%s\n", selector)
fmt.Fprintf(out, "Parallelism:\t%d\n", *job.Spec.Parallelism) fmt.Fprintf(out, "Parallelism:\t%d\n", *job.Spec.Parallelism)
fmt.Fprintf(out, "Completions:\t%d\n", *job.Spec.Completions) fmt.Fprintf(out, "Completions:\t%d\n", *job.Spec.Completions)
if job.Status.StartTime != nil {
fmt.Fprintf(out, "Start Time:\t%s\n", job.Status.StartTime.Time.Format(time.RFC1123Z))
}
if job.Spec.ActiveDeadlineSeconds != nil {
fmt.Fprintf(out, "Active Deadline Seconds:\t%ds\n", *job.Spec.ActiveDeadlineSeconds)
}
fmt.Fprintf(out, "Labels:\t%s\n", labels.FormatLabels(job.Labels)) fmt.Fprintf(out, "Labels:\t%s\n", labels.FormatLabels(job.Labels))
fmt.Fprintf(out, "Pods Statuses:\t%d Running / %d Succeeded / %d Failed\n", job.Status.Active, job.Status.Succeeded, job.Status.Failed) fmt.Fprintf(out, "Pods Statuses:\t%d Running / %d Succeeded / %d Failed\n", job.Status.Active, job.Status.Succeeded, job.Status.Failed)
describeVolumes(job.Spec.Template.Spec.Volumes, out) describeVolumes(job.Spec.Template.Spec.Volumes, out)
......
...@@ -156,18 +156,30 @@ func (x *TestResource) CodecEncodeSelf(e *codec1978.Encoder) { ...@@ -156,18 +156,30 @@ func (x *TestResource) CodecEncodeSelf(e *codec1978.Encoder) {
if yyr2 || yy2arr2 { if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234) z.EncSendContainerState(codecSelfer_containerArrayElem1234)
yy10 := &x.ObjectMeta yy10 := &x.ObjectMeta
yy10.CodecEncodeSelf(e) yym11 := z.EncBinary()
_ = yym11
if false {
} else if z.HasExtensions() && z.EncExt(yy10) {
} else {
z.EncFallback(yy10)
}
} else { } else {
z.EncSendContainerState(codecSelfer_containerMapKey1234) z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("metadata")) r.EncodeString(codecSelferC_UTF81234, string("metadata"))
z.EncSendContainerState(codecSelfer_containerMapValue1234) z.EncSendContainerState(codecSelfer_containerMapValue1234)
yy11 := &x.ObjectMeta yy12 := &x.ObjectMeta
yy11.CodecEncodeSelf(e) yym13 := z.EncBinary()
_ = yym13
if false {
} else if z.HasExtensions() && z.EncExt(yy12) {
} else {
z.EncFallback(yy12)
}
} }
if yyr2 || yy2arr2 { if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234) z.EncSendContainerState(codecSelfer_containerArrayElem1234)
yym13 := z.EncBinary() yym15 := z.EncBinary()
_ = yym13 _ = yym15
if false { if false {
} else { } else {
r.EncodeInt(int64(x.Value)) r.EncodeInt(int64(x.Value))
...@@ -176,8 +188,8 @@ func (x *TestResource) CodecEncodeSelf(e *codec1978.Encoder) { ...@@ -176,8 +188,8 @@ func (x *TestResource) CodecEncodeSelf(e *codec1978.Encoder) {
z.EncSendContainerState(codecSelfer_containerMapKey1234) z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("value")) r.EncodeString(codecSelferC_UTF81234, string("value"))
z.EncSendContainerState(codecSelfer_containerMapValue1234) z.EncSendContainerState(codecSelfer_containerMapValue1234)
yym14 := z.EncBinary() yym16 := z.EncBinary()
_ = yym14 _ = yym16
if false { if false {
} else { } else {
r.EncodeInt(int64(x.Value)) r.EncodeInt(int64(x.Value))
...@@ -196,25 +208,25 @@ func (x *TestResource) CodecDecodeSelf(d *codec1978.Decoder) { ...@@ -196,25 +208,25 @@ func (x *TestResource) CodecDecodeSelf(d *codec1978.Decoder) {
var h codecSelfer1234 var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d) z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r _, _, _ = h, z, r
yym15 := z.DecBinary() yym17 := z.DecBinary()
_ = yym15 _ = yym17
if false { if false {
} else if z.HasExtensions() && z.DecExt(x) { } else if z.HasExtensions() && z.DecExt(x) {
} else { } else {
yyct16 := r.ContainerType() yyct18 := r.ContainerType()
if yyct16 == codecSelferValueTypeMap1234 { if yyct18 == codecSelferValueTypeMap1234 {
yyl16 := r.ReadMapStart() yyl18 := r.ReadMapStart()
if yyl16 == 0 { if yyl18 == 0 {
z.DecSendContainerState(codecSelfer_containerMapEnd1234) z.DecSendContainerState(codecSelfer_containerMapEnd1234)
} else { } else {
x.codecDecodeSelfFromMap(yyl16, d) x.codecDecodeSelfFromMap(yyl18, d)
} }
} else if yyct16 == codecSelferValueTypeArray1234 { } else if yyct18 == codecSelferValueTypeArray1234 {
yyl16 := r.ReadArrayStart() yyl18 := r.ReadArrayStart()
if yyl16 == 0 { if yyl18 == 0 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234) z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
} else { } else {
x.codecDecodeSelfFromArray(yyl16, d) x.codecDecodeSelfFromArray(yyl18, d)
} }
} else { } else {
panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234)
...@@ -226,12 +238,12 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { ...@@ -226,12 +238,12 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
var h codecSelfer1234 var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d) z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r _, _, _ = h, z, r
var yys17Slc = z.DecScratchBuffer() // default slice to decode into var yys19Slc = z.DecScratchBuffer() // default slice to decode into
_ = yys17Slc _ = yys19Slc
var yyhl17 bool = l >= 0 var yyhl19 bool = l >= 0
for yyj17 := 0; ; yyj17++ { for yyj19 := 0; ; yyj19++ {
if yyhl17 { if yyhl19 {
if yyj17 >= l { if yyj19 >= l {
break break
} }
} else { } else {
...@@ -240,10 +252,10 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { ...@@ -240,10 +252,10 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
} }
} }
z.DecSendContainerState(codecSelfer_containerMapKey1234) z.DecSendContainerState(codecSelfer_containerMapKey1234)
yys17Slc = r.DecodeBytes(yys17Slc, true, true) yys19Slc = r.DecodeBytes(yys19Slc, true, true)
yys17 := string(yys17Slc) yys19 := string(yys19Slc)
z.DecSendContainerState(codecSelfer_containerMapValue1234) z.DecSendContainerState(codecSelfer_containerMapValue1234)
switch yys17 { switch yys19 {
case "kind": case "kind":
if r.TryDecodeAsNil() { if r.TryDecodeAsNil() {
x.Kind = "" x.Kind = ""
...@@ -260,8 +272,14 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { ...@@ -260,8 +272,14 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
if r.TryDecodeAsNil() { if r.TryDecodeAsNil() {
x.ObjectMeta = pkg2_api.ObjectMeta{} x.ObjectMeta = pkg2_api.ObjectMeta{}
} else { } else {
yyv20 := &x.ObjectMeta yyv22 := &x.ObjectMeta
yyv20.CodecDecodeSelf(d) yym23 := z.DecBinary()
_ = yym23
if false {
} else if z.HasExtensions() && z.DecExt(yyv22) {
} else {
z.DecFallback(yyv22, false)
}
} }
case "value": case "value":
if r.TryDecodeAsNil() { if r.TryDecodeAsNil() {
...@@ -270,9 +288,9 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { ...@@ -270,9 +288,9 @@ func (x *TestResource) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
x.Value = int(r.DecodeInt(codecSelferBitsize1234)) x.Value = int(r.DecodeInt(codecSelferBitsize1234))
} }
default: default:
z.DecStructFieldNotFound(-1, yys17) z.DecStructFieldNotFound(-1, yys19)
} // end switch yys17 } // end switch yys19
} // end for yyj17 } // end for yyj19
z.DecSendContainerState(codecSelfer_containerMapEnd1234) z.DecSendContainerState(codecSelfer_containerMapEnd1234)
} }
...@@ -280,16 +298,16 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { ...@@ -280,16 +298,16 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
var h codecSelfer1234 var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d) z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r _, _, _ = h, z, r
var yyj22 int var yyj25 int
var yyb22 bool var yyb25 bool
var yyhl22 bool = l >= 0 var yyhl25 bool = l >= 0
yyj22++ yyj25++
if yyhl22 { if yyhl25 {
yyb22 = yyj22 > l yyb25 = yyj25 > l
} else { } else {
yyb22 = r.CheckBreak() yyb25 = r.CheckBreak()
} }
if yyb22 { if yyb25 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234) z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return return
} }
...@@ -299,13 +317,13 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { ...@@ -299,13 +317,13 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
} else { } else {
x.Kind = string(r.DecodeString()) x.Kind = string(r.DecodeString())
} }
yyj22++ yyj25++
if yyhl22 { if yyhl25 {
yyb22 = yyj22 > l yyb25 = yyj25 > l
} else { } else {
yyb22 = r.CheckBreak() yyb25 = r.CheckBreak()
} }
if yyb22 { if yyb25 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234) z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return return
} }
...@@ -315,13 +333,13 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { ...@@ -315,13 +333,13 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
} else { } else {
x.APIVersion = string(r.DecodeString()) x.APIVersion = string(r.DecodeString())
} }
yyj22++ yyj25++
if yyhl22 { if yyhl25 {
yyb22 = yyj22 > l yyb25 = yyj25 > l
} else { } else {
yyb22 = r.CheckBreak() yyb25 = r.CheckBreak()
} }
if yyb22 { if yyb25 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234) z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return return
} }
...@@ -329,16 +347,22 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { ...@@ -329,16 +347,22 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
if r.TryDecodeAsNil() { if r.TryDecodeAsNil() {
x.ObjectMeta = pkg2_api.ObjectMeta{} x.ObjectMeta = pkg2_api.ObjectMeta{}
} else { } else {
yyv25 := &x.ObjectMeta yyv28 := &x.ObjectMeta
yyv25.CodecDecodeSelf(d) yym29 := z.DecBinary()
_ = yym29
if false {
} else if z.HasExtensions() && z.DecExt(yyv28) {
} else {
z.DecFallback(yyv28, false)
}
} }
yyj22++ yyj25++
if yyhl22 { if yyhl25 {
yyb22 = yyj22 > l yyb25 = yyj25 > l
} else { } else {
yyb22 = r.CheckBreak() yyb25 = r.CheckBreak()
} }
if yyb22 { if yyb25 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234) z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return return
} }
...@@ -349,17 +373,17 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { ...@@ -349,17 +373,17 @@ func (x *TestResource) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) {
x.Value = int(r.DecodeInt(codecSelferBitsize1234)) x.Value = int(r.DecodeInt(codecSelferBitsize1234))
} }
for { for {
yyj22++ yyj25++
if yyhl22 { if yyhl25 {
yyb22 = yyj22 > l yyb25 = yyj25 > l
} else { } else {
yyb22 = r.CheckBreak() yyb25 = r.CheckBreak()
} }
if yyb22 { if yyb25 {
break break
} }
z.DecSendContainerState(codecSelfer_containerArrayElem1234) z.DecSendContainerState(codecSelfer_containerArrayElem1234)
z.DecStructFieldNotFound(yyj22-1, "") z.DecStructFieldNotFound(yyj25-1, "")
} }
z.DecSendContainerState(codecSelfer_containerArrayEnd1234) z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
} }
...@@ -182,6 +182,19 @@ var _ = Describe("Job", func() { ...@@ -182,6 +182,19 @@ var _ = Describe("Job", func() {
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
Expect(errors.IsNotFound(err)).To(BeTrue()) Expect(errors.IsNotFound(err)).To(BeTrue())
}) })
It("should fail a job", func() {
By("Creating a job")
job := newTestJob("notTerminate", "foo", api.RestartPolicyNever, parallelism, completions)
activeDeadlineSeconds := int64(10)
job.Spec.ActiveDeadlineSeconds = &activeDeadlineSeconds
job, err := createJob(f.Client, f.Namespace.Name, job)
Expect(err).NotTo(HaveOccurred())
By("Ensuring job was failed")
err = waitForJobFail(f.Client, f.Namespace.Name, job.Name)
Expect(err).NotTo(HaveOccurred())
})
}) })
// newTestJob returns a job which does one of several testing behaviors. // newTestJob returns a job which does one of several testing behaviors.
...@@ -283,3 +296,19 @@ func waitForJobFinish(c *client.Client, ns, jobName string, completions int) err ...@@ -283,3 +296,19 @@ func waitForJobFinish(c *client.Client, ns, jobName string, completions int) err
return curr.Status.Succeeded == completions, nil return curr.Status.Succeeded == completions, nil
}) })
} }
// Wait for job fail.
func waitForJobFail(c *client.Client, ns, jobName string) error {
return wait.Poll(poll, jobTimeout, func() (bool, error) {
curr, err := c.Extensions().Jobs(ns).Get(jobName)
if err != nil {
return false, err
}
for _, c := range curr.Status.Conditions {
if c.Type == extensions.JobFailed && c.Status == api.ConditionTrue {
return true, nil
}
}
return false, nil
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment