cli: prevent panic if job node pool is nil (#17571)

If the `nomad` CLI is used to access a cluster running a version that
does not include node pools the command will `nil` panic when trying to
resolve the job's node pool.
This commit is contained in:
Luiz Aoqui 2023-06-16 17:08:36 -04:00 committed by GitHub
parent d5aa72190f
commit d07f9ae2fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -167,6 +167,11 @@ func (c *JobStatusCommand) Run(args []string) int {
periodic := job.IsPeriodic() periodic := job.IsPeriodic()
parameterized := job.IsParameterized() parameterized := job.IsParameterized()
nodePool := ""
if job.NodePool != nil {
nodePool = *job.NodePool
}
// Format the job info // Format the job info
basic := []string{ basic := []string{
fmt.Sprintf("ID|%s", *job.ID), fmt.Sprintf("ID|%s", *job.ID),
@ -176,7 +181,7 @@ func (c *JobStatusCommand) Run(args []string) int {
fmt.Sprintf("Priority|%d", *job.Priority), fmt.Sprintf("Priority|%d", *job.Priority),
fmt.Sprintf("Datacenters|%s", strings.Join(job.Datacenters, ",")), fmt.Sprintf("Datacenters|%s", strings.Join(job.Datacenters, ",")),
fmt.Sprintf("Namespace|%s", *job.Namespace), fmt.Sprintf("Namespace|%s", *job.Namespace),
fmt.Sprintf("Node Pool|%s", *job.NodePool), fmt.Sprintf("Node Pool|%s", nodePool),
fmt.Sprintf("Status|%s", getStatusString(*job.Status, job.Stop)), fmt.Sprintf("Status|%s", getStatusString(*job.Status, job.Stop)),
fmt.Sprintf("Periodic|%v", periodic), fmt.Sprintf("Periodic|%v", periodic),
fmt.Sprintf("Parameterized|%v", parameterized), fmt.Sprintf("Parameterized|%v", parameterized),