Reaper and scaler for jobs

This commit is contained in:
Maciej Szulik
2015-09-16 17:32:59 +02:00
parent 28585bc699
commit 48775319d9
9 changed files with 473 additions and 66 deletions

View File

@@ -18,6 +18,7 @@ package unversioned
import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/experimental"
"k8s.io/kubernetes/pkg/util/wait"
)
@@ -41,3 +42,23 @@ func ControllerHasDesiredReplicas(c Interface, controller *api.ReplicationContro
return ctrl.Status.ObservedGeneration >= desiredGeneration && ctrl.Status.Replicas == ctrl.Spec.Replicas, nil
}
}
// JobHasDesiredParallelism returns a condition that will be true if the desired parallelism count
// for a job equals the current active counts or is less by an appropriate successful/unsuccessful count.
func JobHasDesiredParallelism(c Interface, job *experimental.Job) wait.ConditionFunc {
return func() (bool, error) {
job, err := c.Experimental().Jobs(job.Namespace).Get(job.Name)
if err != nil {
return false, err
}
// desired parallelism can be either the exact number, in which case return immediately
if job.Status.Active == *job.Spec.Parallelism {
return true, nil
}
// otherwise count successful
progress := *job.Spec.Completions - job.Status.Active - job.Status.Successful
return progress == 0, nil
}
}