Skip to content

Commit

Permalink
cli: Support client only in version sub-command
Browse files Browse the repository at this point in the history
This is similar to what kubectl offers (i.e. kubectl version --client).
One benefit is to have faster response time if the current kubernetes
context is not valid or no cilium installed.

Thanks to Shane O'Donnell for suggestion.

Signed-off-by: Tam Mach <[email protected]>
  • Loading branch information
sayboras authored and tklauser committed Jan 10, 2023
1 parent 7f3f732 commit d6447fb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func getLatestStableVersion() string {
}

func newCmdVersion() *cobra.Command {
var clientOnly bool
cmd := &cobra.Command{
Use: "version",
Short: "Display detailed version information",
Expand All @@ -46,6 +47,9 @@ func newCmdVersion() *cobra.Command {
fmt.Printf("cilium-cli: %s compiled with %v on %v/%v\n", Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("cilium image (default): %s\n", defaults.Version)
fmt.Printf("cilium image (stable): %s\n", getLatestStableVersion())
if clientOnly {
return nil
}
version, err := k8sClient.GetRunningCiliumVersion(context.Background(), namespace)
if version == "" || err != nil {
fmt.Printf("cilium image (running): unknown. Unable to obtain cilium version, no cilium pods found in namespace %q\n", namespace)
Expand All @@ -56,5 +60,6 @@ func newCmdVersion() *cobra.Command {
},
}

cmd.Flags().BoolVar(&clientOnly, "client", false, "If true, shows client version only (no server required)")
return cmd
}

0 comments on commit d6447fb

Please sign in to comment.