From a1ba068e1f08742645606a695bda1525b5948af7 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 20 Apr 2023 17:33:29 -0700 Subject: [PATCH] cli: fix panic on job plan when -diff=false (#16944) PR #14492 introduced a new check to return 0 when the `nomad job plan` command returns a diff of type `None`. But the `-diff` CLI flag was also being used to control whether the plan request should return the diff of not instead of just controlling if the diff was printed. This means that when `-diff=false` is set the response does not include any diff information, and so the new check panics. This commit fixes the problem by always requesting a diff and using the `-diff` only for controlling output, as it's currently documented. --- .changelog/16944.txt | 3 +++ command/job_plan.go | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 .changelog/16944.txt diff --git a/.changelog/16944.txt b/.changelog/16944.txt new file mode 100644 index 000000000..ad5a743c0 --- /dev/null +++ b/.changelog/16944.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Fix panic on job plan when -diff=false +``` diff --git a/command/job_plan.go b/command/job_plan.go index d3d45fbd0..54e70b744 100644 --- a/command/job_plan.go +++ b/command/job_plan.go @@ -237,9 +237,9 @@ func (c *JobPlanCommand) Run(args []string) int { } // Setup the options - opts := &api.PlanOptions{} - if diff { - opts.Diff = true + opts := &api.PlanOptions{ + // Always request the diff so we can tell if there are changes. + Diff: true, } if policyOverride { opts.PolicyOverride = true