Skip to content

Commit

Permalink
internal/cli/cmd: report latest stable image version
Browse files Browse the repository at this point in the history
As of cilium/cilium#16453 cilium provides a
stable.txt file in the master branch pointing to the latest stable
version. Use it to report that latest stable version in `cilium
version`.

Suggested-by: Robin Hahling <robin.hahling@gw-computing.net>
Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser committed Jul 8, 2021
1 parent 5c7fca2 commit 8e408b5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ package cmd

import (
"fmt"
"io"
"net/http"
"runtime"
"strings"

"github.com/cilium/cilium-cli/defaults"

Expand All @@ -33,6 +36,21 @@ var (
GitHash string
)

func getLatestStableVersion() string {
resp, err := http.Get("https://raw.githubusercontent.com/cilium/cilium/master/stable.txt")
if err != nil {
return "unknown"
}
defer resp.Body.Close()

b, err := io.ReadAll(resp.Body)
if err != nil {
return "unknown"
}

return strings.TrimSpace(string(b))
}

func newCmdVersion() *cobra.Command {
return &cobra.Command{
Use: "version",
Expand All @@ -50,6 +68,7 @@ func newCmdVersion() *cobra.Command {
// the cluster, if any. See https://github.com/cilium/cilium-cli/issues/131
fmt.Printf("cilium-cli: v%s%s compiled with %v on %v/%v\n", Version, gitInfo, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("cilium image (default): %s\n", defaults.Version)
fmt.Printf("cilium image (stable): %s\n", getLatestStableVersion())
},
}
}

0 comments on commit 8e408b5

Please sign in to comment.