WarnMatchedProvisioners warns the user if there are no provisioners that match the requested tags for a given provisioner job. If the job is not pending, it is ignored.
(w io.Writer, mp *codersdk.MatchedProvisioners, job codersdk.ProvisionerJob)
| 28 | // match the requested tags for a given provisioner job. |
| 29 | // If the job is not pending, it is ignored. |
| 30 | func WarnMatchedProvisioners(w io.Writer, mp *codersdk.MatchedProvisioners, job codersdk.ProvisionerJob) { |
| 31 | if mp == nil { |
| 32 | // Nothing in the response, nothing to do here! |
| 33 | return |
| 34 | } |
| 35 | if job.Status != codersdk.ProvisionerJobPending { |
| 36 | // Only warn if the job is pending. |
| 37 | return |
| 38 | } |
| 39 | var tagsJSON strings.Builder |
| 40 | if err := json.NewEncoder(&tagsJSON).Encode(job.Tags); err != nil { |
| 41 | // Fall back to the less-pretty string representation. |
| 42 | tagsJSON.Reset() |
| 43 | _, _ = tagsJSON.WriteString(fmt.Sprintf("%v", job.Tags)) |
| 44 | } |
| 45 | if mp.Count == 0 { |
| 46 | cliui.Warnf(w, warnNoMatchedProvisioners, job.ID, tagsJSON.String()) |
| 47 | return |
| 48 | } |
| 49 | if mp.Available == 0 { |
| 50 | cliui.Warnf(w, warnNoAvailableProvisioners, job.ID, strings.TrimSpace(tagsJSON.String()), mp.MostRecentlySeen.Time) |
| 51 | return |
| 52 | } |
| 53 | } |