forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
55 lines (44 loc) · 1.24 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package version
import (
"fmt"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"kubevirt.io/kubevirt/pkg/kubecli"
"kubevirt.io/kubevirt/pkg/version"
"kubevirt.io/kubevirt/pkg/virtctl/templates"
)
func VersionCommand(clientConfig clientcmd.ClientConfig) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the client and server version information",
Example: usage(),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
v := Version{clientConfig: clientConfig}
return v.Run(cmd, args)
},
}
cmd.SetUsageTemplate(templates.UsageTemplate())
return cmd
}
func usage() string {
usage := "# Print the client and server versions for the current context \n"
usage += "virtctl version"
return usage
}
type Version struct {
clientConfig clientcmd.ClientConfig
}
func (v *Version) Run(cmd *cobra.Command, args []string) error {
fmt.Printf("Client Version: %s\n", fmt.Sprintf("%#v", version.Get()))
virCli, err := kubecli.GetKubevirtClientFromClientConfig(v.clientConfig)
if err != nil {
return err
}
serverInfo, err := virCli.ServerVersion().Get()
if err != nil {
return err
}
fmt.Printf("Server Version: %s\n", fmt.Sprintf("%#v", serverInfo))
return nil
}