in pkg/controllers/job/job_controller_util.go [151:207]
func applyPolicies(job *batch.Job, req *apis.Request) v1alpha1.Action {
if len(req.Action) != 0 {
return req.Action
}
if req.Event == v1alpha1.OutOfSyncEvent {
return v1alpha1.SyncJobAction
}
// For all the requests triggered from discarded job resources will perform sync action instead
if req.JobVersion < job.Status.Version {
klog.Infof("Request %s is outdated, will perform sync instead.", req)
return v1alpha1.SyncJobAction
}
// Overwrite Job level policies
if len(req.TaskName) != 0 {
// Parse task level policies
for _, task := range job.Spec.Tasks {
if task.Name == req.TaskName {
for _, policy := range task.Policies {
policyEvents := getEventlist(policy)
if len(policyEvents) > 0 && len(req.Event) > 0 {
if checkEventExist(policyEvents, req.Event) || checkEventExist(policyEvents, v1alpha1.AnyEvent) {
return policy.Action
}
}
// 0 is not an error code, is prevented in validation admission controller
if policy.ExitCode != nil && *policy.ExitCode == req.ExitCode {
return policy.Action
}
}
break
}
}
}
// Parse Job level policies
for _, policy := range job.Spec.Policies {
policyEvents := getEventlist(policy)
if len(policyEvents) > 0 && len(req.Event) > 0 {
if checkEventExist(policyEvents, req.Event) || checkEventExist(policyEvents, v1alpha1.AnyEvent) {
return policy.Action
}
}
// 0 is not an error code, is prevented in validation admission controller
if policy.ExitCode != nil && *policy.ExitCode == req.ExitCode {
return policy.Action
}
}
return v1alpha1.SyncJobAction
}