Skip to content

Commit

Permalink
Sort output of plan status command
Browse files Browse the repository at this point in the history
Alphabetise (by plan) the output of the plan status command so that it's
consistent each time it's run.  This helps human operators when
monitoring a deployment.

Signed-off-by: Nick Jones <nick@dischord.org>
  • Loading branch information
yankcrime committed Feb 29, 2020
1 parent f0eec84 commit 995e005
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/kudoctl/cmd/plan/plan_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plan

import (
"fmt"
"sort"

"github.com/xlab/treeprint"

Expand Down Expand Up @@ -63,13 +64,19 @@ func status(kc *kudo.Client, options *Options, ns string) error {
rootDisplay := fmt.Sprintf("%s (Operator-Version: \"%s\" Active-Plan: \"%s\")", instance.Name, instance.Spec.OperatorVersion.Name, lastPlanStatus.Name)
rootBranchName := tree.AddBranch(rootDisplay)

for name, plan := range ov.Spec.Plans {
if name == lastPlanStatus.Name {
plans := make([]string, 0, len(ov.Spec.Plans))
for k := range ov.Spec.Plans {
plans = append(plans, k)
}
sort.Strings(plans)

for _, plan := range plans {
if plan == lastPlanStatus.Name {
var planDisplay string
if lastPlanStatus.LastUpdatedTimestamp != nil {
planDisplay = fmt.Sprintf("Plan %s (%s strategy) [%s]%s, last updated %s", name, plan.Strategy, lastPlanStatus.Status, printMessageIfAvailable(lastPlanStatus.Message), lastPlanStatus.LastUpdatedTimestamp.Format("2006-01-02 15:04:05"))
planDisplay = fmt.Sprintf("Plan %s (%s strategy) [%s]%s, last updated %s", plan, ov.Spec.Plans[plan].Strategy, lastPlanStatus.Status, printMessageIfAvailable(lastPlanStatus.Message), lastPlanStatus.LastUpdatedTimestamp.Format("2006-01-02 15:04:05"))
} else {
planDisplay = fmt.Sprintf("Plan %s (%s strategy) [%s]%s", name, plan.Strategy, lastPlanStatus.Status, printMessageIfAvailable(lastPlanStatus.Message))
planDisplay = fmt.Sprintf("Plan %s (%s strategy) [%s]%s", plan, ov.Spec.Plans[plan].Strategy, lastPlanStatus.Status, printMessageIfAvailable(lastPlanStatus.Message))
}

planBranchName := rootBranchName.AddBranch(planDisplay)
Expand All @@ -82,9 +89,9 @@ func status(kc *kudo.Client, options *Options, ns string) error {
}
}
} else {
planDisplay := fmt.Sprintf("Plan %s (%s strategy) [NOT ACTIVE]", name, plan.Strategy)
planDisplay := fmt.Sprintf("Plan %s (%s strategy) [NOT ACTIVE]", plan, ov.Spec.Plans[plan].Strategy)
planBranchName := rootBranchName.AddBranch(planDisplay)
for _, phase := range plan.Phases {
for _, phase := range ov.Spec.Plans[plan].Phases {
phaseDisplay := fmt.Sprintf("Phase %s (%s strategy) [NOT ACTIVE]", phase.Name, phase.Strategy)
phaseBranchName := planBranchName.AddBranch(phaseDisplay)
for _, steps := range phase.Steps {
Expand Down

0 comments on commit 995e005

Please sign in to comment.