Fix plan history bug
@@ -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"
)
@@ -44,23 +42,26 @@ func planHistory(options *Options, settings *env.Settings) error {
return err
}
instance, err := kc.GetInstance(options.Instance, 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", 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)
