Skip to content

Commit

Permalink
Fix nil pointer panic (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mir Shahriar authored and tamalsaha committed May 18, 2017
1 parent 2579f3c commit 5bb308d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 7 additions & 8 deletions pkg/cmd/describer/k8sdb_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package describer
import (
"fmt"
"io"
"time"

"github.com/golang/glog"
tapi "github.com/k8sdb/apimachinery/api"
Expand Down Expand Up @@ -53,7 +52,7 @@ func (d *humanReadableDescriber) describeElastic(item *tapi.Elastic, describerSe
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", item.Name)
fmt.Fprintf(out, "Namespace:\t%s\n", item.Namespace)
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", item.CreationTimestamp.Time.Format(time.RFC1123Z))
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", timeToString(&item.CreationTimestamp))
if item.Labels != nil {
printLabelsMultiline(out, "Labels:", item.Labels)
}
Expand Down Expand Up @@ -119,7 +118,7 @@ func (d *humanReadableDescriber) describePostgres(item *tapi.Postgres, describer
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", item.Name)
fmt.Fprintf(out, "Namespace:\t%s\n", item.Namespace)
fmt.Fprintf(out, "StartTimestamp:\t%s\n", item.CreationTimestamp.Time.Format(time.RFC1123Z))
fmt.Fprintf(out, "StartTimestamp:\t%s\n", timeToString(&item.CreationTimestamp))
if item.Labels != nil {
printLabelsMultiline(out, "Labels:", item.Labels)
}
Expand Down Expand Up @@ -173,9 +172,9 @@ func (d *humanReadableDescriber) describeSnapshot(item *tapi.Snapshot, describer
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", item.Name)
fmt.Fprintf(out, "Namespace:\t%s\n", item.Namespace)
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", item.CreationTimestamp.Format(time.RFC1123Z))
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", timeToString(&item.CreationTimestamp))
if item.Status.CompletionTime != nil {
fmt.Fprintf(out, "CompletionTimestamp:\t%s\n", item.Status.CompletionTime.Format(time.RFC1123Z))
fmt.Fprintf(out, "CompletionTimestamp:\t%s\n", timeToString(item.Status.CompletionTime))
}
if item.Labels != nil {
printLabelsMultiline(out, "Labels:", item.Labels)
Expand Down Expand Up @@ -220,12 +219,12 @@ func (d *humanReadableDescriber) describeDeletedDatabase(item *tapi.DeletedDatab
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", item.Name)
fmt.Fprintf(out, "Namespace:\t%s\n", item.Namespace)
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", item.CreationTimestamp.Format(time.RFC1123Z))
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", timeToString(&item.CreationTimestamp))
if item.Status.DeletionTime != nil {
fmt.Fprintf(out, "DeletionTimestamp:\t%s\n", item.Status.DeletionTime.Format(time.RFC1123Z))
fmt.Fprintf(out, "DeletionTimestamp:\t%s\n", timeToString(item.Status.DeletionTime))
}
if item.Status.WipeOutTime != nil {
fmt.Fprintf(out, "WipeOutTimestamp:\t%s\n", item.Status.WipeOutTime.Format(time.RFC1123Z))
fmt.Fprintf(out, "WipeOutTimestamp:\t%s\n", timeToString(item.Status.WipeOutTime))
}
if item.Labels != nil {
printLabelsMultiline(out, "Labels:", item.Labels)
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/describer/kube_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"sort"
"strings"
"time"

"github.com/k8sdb/kubedb/pkg/cmd/printer"
"github.com/k8sdb/kubedb/pkg/cmd/util"
Expand Down Expand Up @@ -43,7 +42,7 @@ func (d *humanReadableDescriber) describeStatefulSet(namespace, name string, out
fmt.Fprint(out, "StatefulSet:\t\n")
fmt.Fprintf(out, " Name:\t%s\n", ps.Name)
fmt.Fprintf(out, " Replicas:\t%d current / %d desired\n", ps.Status.Replicas, ps.Spec.Replicas)
fmt.Fprintf(out, " CreationTimestamp:\t%s\n", ps.CreationTimestamp.Time.Format(time.RFC1123Z))
fmt.Fprintf(out, " CreationTimestamp:\t%s\n", timeToString(&ps.CreationTimestamp))
fmt.Fprintf(out, " Pods Status:\t%d Running / %d Waiting / %d Succeeded / %d Failed\n", running, waiting, succeeded, failed)
}

Expand Down

0 comments on commit 5bb308d

Please sign in to comment.