Skip to content

Commit

Permalink
Include phase strategy in plan status output (#1173)
Browse files Browse the repository at this point in the history
Phase strategy can be defined independently of that for a plan, so this
commit includes this in the output so that the Operator behaviour is
less confusing to the user.
  • Loading branch information
yankcrime authored and alenkacz committed Dec 17, 2019
1 parent e5361cb commit e2d383f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions pkg/kudoctl/cmd/plan/plan_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/xlab/treeprint"

"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1"
"github.com/kudobuilder/kudo/pkg/kudoctl/env"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
)
Expand Down Expand Up @@ -48,6 +49,17 @@ func status(kc *kudo.Client, options *Options, ns string) error {
return nil
}

getPhaseStrategy := func(s string) v1beta1.Ordering {
for _, plan := range ov.Spec.Plans {
for _, phase := range plan.Phases {
if phase.Name == s {
return phase.Strategy
}
}
}
return ""
}

rootDisplay := fmt.Sprintf("%s (Operator-Version: \"%s\" Active-Plan: \"%s\")", instance.Name, instance.Spec.OperatorVersion.Name, lastPlanStatus.Name)
rootBranchName := tree.AddBranch(rootDisplay)

Expand All @@ -56,7 +68,7 @@ func status(kc *kudo.Client, options *Options, ns string) error {
planDisplay := fmt.Sprintf("Plan %s (%s strategy) [%s]%s", name, plan.Strategy, lastPlanStatus.Status, printMessageIfAvailable(lastPlanStatus.Message))
planBranchName := rootBranchName.AddBranch(planDisplay)
for _, phase := range lastPlanStatus.Phases {
phaseDisplay := fmt.Sprintf("Phase %s [%s]%s", phase.Name, phase.Status, printMessageIfAvailable(phase.Message))
phaseDisplay := fmt.Sprintf("Phase %s (%s strategy) [%s]%s", phase.Name, getPhaseStrategy(phase.Name), phase.Status, printMessageIfAvailable(phase.Message))
phaseBranchName := planBranchName.AddBranch(phaseDisplay)
for _, steps := range phase.Steps {
stepsDisplay := fmt.Sprintf("Step %s [%s]%s", steps.Name, steps.Status, printMessageIfAvailable(steps.Message))
Expand All @@ -69,13 +81,9 @@ func status(kc *kudo.Client, options *Options, ns string) error {
for _, phase := range plan.Phases {
phaseDisplay := fmt.Sprintf("Phase %s (%s strategy) [NOT ACTIVE]", phase.Name, phase.Strategy)
phaseBranchName := planBranchName.AddBranch(phaseDisplay)
for _, steps := range plan.Phases {
stepsDisplay := fmt.Sprintf("Step %s (%s strategy) [NOT ACTIVE]", steps.Name, steps.Strategy)
stepBranchName := phaseBranchName.AddBranch(stepsDisplay)
for _, step := range steps.Steps {
stepDisplay := fmt.Sprintf("%s [NOT ACTIVE]", step.Name)
stepBranchName.AddBranch(stepDisplay)
}
for _, steps := range phase.Steps {
stepDisplay := fmt.Sprintf("Step %s [NOT ACTIVE]", steps.Name)
phaseBranchName.AddBranch(stepDisplay)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kudoctl/cmd/plan/plan_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestStatus(t *testing.T) {
.
└── test (Operator-Version: "test-1.0" Active-Plan: "deploy")
└── Plan deploy ( strategy) [FATAL_ERROR]
└── Phase deploy [FATAL_ERROR]
└── Phase deploy ( strategy) [FATAL_ERROR]
└── Step deploy [FATAL_ERROR] (error detail)
`},
Expand Down

0 comments on commit e2d383f

Please sign in to comment.