mirror of https://github.com/k3s-io/k3s
Fix job status conditions bloat
When a job is complete, the controller will indefinitely update its conditions with a Complete condition. This change makes the controller exit the reconcilation as soon as the job is already found to be marked as complete.pull/6/head
parent
67ac4e3838
commit
dd84bba64c
|
@ -330,11 +330,11 @@ func (jm *JobController) syncJob(key string) error {
|
|||
now := unversioned.Now()
|
||||
job.Status.StartTime = &now
|
||||
}
|
||||
// if job was finished previously, we don't want to redo the termination
|
||||
if isJobFinished(&job) {
|
||||
return nil
|
||||
}
|
||||
if pastActiveDeadline(&job) {
|
||||
// if job was finished previously, we don't want to redo the termination
|
||||
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
|
||||
|
|
|
@ -359,7 +359,31 @@ func TestSyncPastDeadlineJobFinished(t *testing.T) {
|
|||
if actual != nil {
|
||||
t.Error("Unexpected job modification")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncJobComplete(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
|
||||
|
||||
job := newJob(1, 1)
|
||||
job.Status.Conditions = append(job.Status.Conditions, newCondition(extensions.JobComplete, "", ""))
|
||||
manager.jobStore.Store.Add(job)
|
||||
err := manager.syncJob(getKey(job, t))
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error when syncing jobs %v", err)
|
||||
}
|
||||
uncastJob, _, err := manager.jobStore.Store.Get(job)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error when trying to get job from the store: %v", err)
|
||||
}
|
||||
actual := uncastJob.(*extensions.Job)
|
||||
// Verify that after syncing a complete job, the conditions are the same.
|
||||
if got, expected := len(actual.Status.Conditions), 1; got != expected {
|
||||
t.Fatalf("Unexpected job status conditions amount; expected %d, got %d", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncJobDeleted(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue