Skip to content

Commit

Permalink
Use update info from metrics, improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
maetthu committed May 29, 2021
1 parent 198dd29 commit 63bd92d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ type Image struct {
Image string `json:"image"`
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
IsLatest bool `json:"is_latest"`
Pods []Pod `json:"pods"`
}

func (i *Image) Version() string {
if i.IsLatest {
return fmt.Sprintf("%s (Up to date)", i.CurrentVersion)
}

return fmt.Sprintf("%s > %s", i.CurrentVersion, i.LatestVersion)
}

func (i *Image) AddPod(p Pod) {
i.Pods = append(i.Pods, p)
}
Expand Down Expand Up @@ -66,12 +75,13 @@ var rootCmd = &cobra.Command{
for _, v := range mf {
for _, m := range v.Metric {
labels := map[string]string{}
latest := *m.Gauge.Value > 0

for _, l := range m.Label {
labels[l.GetName()] = l.GetValue()
}

if !displayAll && labels["current_version"] == labels["latest_version"] {
if !displayAll && latest {
continue
}

Expand All @@ -82,6 +92,7 @@ var rootCmd = &cobra.Command{
Image: labels["image"],
CurrentVersion: labels["current_version"],
LatestVersion: labels["latest_version"],
IsLatest: latest,
Pods: []Pod{{
Namespace: labels["namespace"],
Pod: labels["pod"],
Expand Down Expand Up @@ -111,21 +122,19 @@ var rootCmd = &cobra.Command{
table := tablewriter.NewWriter(os.Stdout)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetRowLine(true)
//table.SetRowSeparator("-")

if displayBrief {
table.SetHeader([]string{"Image", "Current", "Latest"})
table.SetHeader([]string{"Image", "Version"})

for _, k := range keys {
table.Append([]string{
images[k].Image,
images[k].CurrentVersion,
images[k].LatestVersion,
images[k].Version(),
})
}

} else {
table.SetHeader([]string{"Image", "Current", "Latest", "Pods"})
table.SetHeader([]string{"Image", "Version", "Pods"})

for _, k := range keys {
pods := []string{}
Expand All @@ -139,8 +148,7 @@ var rootCmd = &cobra.Command{

table.Append([]string{
images[k].Image,
images[k].CurrentVersion,
images[k].LatestVersion,
images[k].Version(),
strings.Join(pods, "\n"),
})
}
Expand Down

0 comments on commit 63bd92d

Please sign in to comment.