Skip to content

Commit

Permalink
[plugin] add age to canary pods cmd (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
celenechang authored Dec 3, 2021
1 parent e08ae24 commit f98add8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/plugin/common/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func printPods(c client.Client, selector labels.Selector, out io.Writer, notRead
continue
}
ready, containers, restarts := containersInfo(&pod)
table.Append([]string{pod.Name, ready, string(pod.Status.Phase), reason, containers, restarts, pod.Spec.NodeName, getNodeReadiness(c, pod.Spec.NodeName)})
table.Append([]string{pod.Name, ready, string(pod.Status.Phase), reason, containers, restarts, pod.Spec.NodeName, getNodeReadiness(c, pod.Spec.NodeName), GetDuration(&pod.ObjectMeta)})
}

table.Render()
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/common/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// newPodsTable returns a table to print pods.
func newPodsTable(out io.Writer) *tablewriter.Table {
table := tablewriter.NewWriter(out)
table.SetHeader([]string{"Pod", "Ready", "Phase", "Reason", "Not ready containers", "Restarts", "Node", "Node Ready"})
table.SetHeader([]string{"Pod", "Ready", "Phase", "Reason", "Not ready containers", "Restarts", "Node", "Node Ready", "Age"})
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetRowLine(false)
Expand Down
8 changes: 8 additions & 0 deletions pkg/plugin/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/hako/durafmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -20,6 +23,11 @@ func IntToString(i int32) string {
return fmt.Sprintf("%d", i)
}

// GetDuration gets uptime duration of a resource.
func GetDuration(obj *metav1.ObjectMeta) string {
return durafmt.ParseShort(time.Since(obj.CreationTimestamp.Time)).String()
}

// isPodNotReady returns whether the pod is ready, returns the the reason if not ready.
func isPodNotReady(pod *corev1.Pod) (bool, string) {
if pod.Status.Phase != corev1.PodRunning {
Expand Down
13 changes: 1 addition & 12 deletions pkg/plugin/get/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@

package get

import (
"time"

"github.com/hako/durafmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/DataDog/extendeddaemonset/api/v1alpha1"
)
import "github.com/DataDog/extendeddaemonset/api/v1alpha1"

func getCanaryRS(eds *v1alpha1.ExtendedDaemonSet) string {
if eds.Status.Canary != nil {
Expand All @@ -21,7 +14,3 @@ func getCanaryRS(eds *v1alpha1.ExtendedDaemonSet) string {

return "-"
}

func getDuration(obj *metav1.ObjectMeta) string {
return durafmt.ParseShort(time.Since(obj.CreationTimestamp.Time)).String()
}
2 changes: 1 addition & 1 deletion pkg/plugin/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (o *getOptions) run() error {

table := newGetTable(o.Out)
for _, item := range edsList.Items {
data := []string{item.Namespace, item.Name, common.IntToString(item.Status.Desired), common.IntToString(item.Status.Current), common.IntToString(item.Status.Ready), common.IntToString(item.Status.UpToDate), common.IntToString(item.Status.Available), common.IntToString(item.Status.IgnoredUnresponsiveNodes), string(item.Status.State), string(item.Status.Reason), item.Status.ActiveReplicaSet, getCanaryRS(&item), getDuration(&item.ObjectMeta)}
data := []string{item.Namespace, item.Name, common.IntToString(item.Status.Desired), common.IntToString(item.Status.Current), common.IntToString(item.Status.Ready), common.IntToString(item.Status.UpToDate), common.IntToString(item.Status.Available), common.IntToString(item.Status.IgnoredUnresponsiveNodes), string(item.Status.State), string(item.Status.Reason), item.Status.ActiveReplicaSet, getCanaryRS(&item), common.GetDuration(&item.ObjectMeta)}
table.Append(data)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/get/geters.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (o *getERSOptions) run() error {

table := newGetERSTable(o.Out)
for _, item := range ersList.Items {
data := []string{item.Namespace, item.Name, common.IntToString(item.Status.Desired), common.IntToString(item.Status.Current), common.IntToString(item.Status.Ready), common.IntToString(item.Status.Available), common.IntToString(item.Status.IgnoredUnresponsiveNodes), item.Status.Status, getDuration(&item.ObjectMeta)}
data := []string{item.Namespace, item.Name, common.IntToString(item.Status.Desired), common.IntToString(item.Status.Current), common.IntToString(item.Status.Ready), common.IntToString(item.Status.Available), common.IntToString(item.Status.IgnoredUnresponsiveNodes), item.Status.Status, common.GetDuration(&item.ObjectMeta)}
table.Append(data)
}

Expand Down

0 comments on commit f98add8

Please sign in to comment.