Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for displaying the running Cilium version #482

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewDefaultCiliumCommand() *cobra.Command {
return nil
}
switch cmd.Name() {
case "completion", "help", "version":
case "completion", "help":
return nil
}

Expand Down
19 changes: 15 additions & 4 deletions internal/cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cmd

import (
"context"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -48,16 +49,26 @@ func getLatestStableVersion() string {
}

func newCmdVersion() *cobra.Command {
return &cobra.Command{
var namespace string
cmd := &cobra.Command{
Use: "version",
Short: "Display detailed version information",
Long: `Displays information about the version of this software.`,
Run: func(cmd *cobra.Command, _ []string) {
// TODO: add support for reporting the Cilium version running in
// the cluster, if any. See https://github.com/cilium/cilium-cli/issues/131
RunE: func(cmd *cobra.Command, args []string) error {
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())
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)
} else {
fmt.Printf("cilium image (running): %s\n", version)
}
return nil
},
}

cmd.Flags().StringVar(&contextName, "context", "", "Kubernetes configuration context")
cmd.Flags().StringVarP(&namespace, "namespace", "n", "kube-system", "Namespace Cilium is running in")
return cmd
}