// ableToRun determines if the Agent can run the provided Job based on // the Agent's desired state. A boolean indicating whether this is the // case or not is returned. The following criteria is used: // - Agent must meet the Job's machine target requirement (if any) // - Job must pass signature verification // - Agent must have all of the Job's required metadata (if any) // - Agent must have all required Peers of the Job scheduled locally (if any) // - Job must not conflict with any other Jobs scheduled to the agent func (ar *AgentReconciler) ableToRun(as *agentState, ms *machine.MachineState, j *job.Job) (bool, string) { log.V(1).Infof("Attempting to determine if able to run Job(%s)", j.Name) if tgt, ok := j.RequiredTarget(); ok && !ms.MatchID(tgt) { return false, fmt.Sprintf("Agent ID %q does not match required %q", ms.ID, tgt) } if !ar.verifyJobSignature(j) { return false, "unable to verify signature" } log.V(1).Infof("Job(%s) has requirements: %s", j.Name, j.Requirements()) metadata := j.RequiredTargetMetadata() if len(metadata) == 0 { log.V(1).Infof("Job(%s) has no required machine metadata", j.Name) } else { log.V(1).Infof("Job(%s) requires machine metadata: %v", j.Name, metadata) if !machine.HasMetadata(ms, metadata) { return false, "local Machine metadata insufficient" } } peers := j.Peers() if len(peers) == 0 { log.V(1).Infof("Job(%s) has no required peers", j.Name) } else { log.V(1).Infof("Job(%s) requires peers: %v", j.Name, peers) for _, peer := range peers { if !as.jobScheduled(peer) { return false, fmt.Sprintf("required peer Job(%s) is not scheduled locally", peer) } } } if cExists, cJobName := as.hasConflict(j.Name, j.Conflicts()); cExists { return false, fmt.Sprintf("found conflict with locally-scheduled Job(%s)", cJobName) } log.V(1).Infof("Determined local Agent is able to run Job(%s)", j.Name) return true, "" }