Skip to content

Commit

Permalink
Backport of plan history fix on unknown instance (#967)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz committed Oct 18, 2019
1 parent b35d39b commit 45fe3da
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/kudoctl/cmd/plan/plan_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package plan
import (
"fmt"

"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
"k8s.io/apimachinery/pkg/api/errors"

"github.com/kudobuilder/kudo/pkg/kudoctl/env"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
"github.com/spf13/cobra"
"github.com/xlab/treeprint"
)
Expand Down Expand Up @@ -43,23 +41,26 @@ func planHistory(options *Options, settings *env.Settings) error {
return err
}
instance, err := kc.GetInstance(options.Instance, options.Namespace)
if errors.IsNotFound(err) {
fmt.Printf("Instance %s/%s does not exist", instance.Namespace, instance.Name)
}
if err != nil {
return err
}
if instance == nil {
return fmt.Errorf("instance %s/%s does not exist", options.Namespace, options.Instance)
}

tree := treeprint.New()
timeLayout := "2006-01-02"
timeLayout := "2006-01-02T15:04:05"

for _, p := range instance.Status.PlanStatus {
msg := "never run"
if p.Status != "" && !p.LastFinishedRun.IsZero() { // plan already finished
msg := "never run" // this is for the cases when status was not yet populated

if !p.LastFinishedRun.IsZero() { // plan already finished
t := p.LastFinishedRun.Format(timeLayout)
msg = fmt.Sprintf("last run at %s", t)
msg = fmt.Sprintf("last finished run at %s (%s)", t, string(p.Status))
} else if p.Status.IsRunning() {
msg = "is running"
} else if p.Status != "" {
msg = string(p.Status)
}
historyDisplay := fmt.Sprintf("%s (%s)", p.Name, msg)
tree.AddBranch(historyDisplay)
Expand Down

0 comments on commit 45fe3da

Please sign in to comment.