Uniformize handling of -server_version flag of kubecfg to match -version.

In particular, add support for -server_version=raw and use matching
format for the output of -version and -server_version.

The "normal" format is essentially defined by (version.Info) String()
method, so future updates to that method will be reflected on both.

Full version information is still available by using the "raw" flag.

Tested:
- Used cluster/kubecfg.sh to query local build and the server.

    $ cluster/kubecfg.sh -version
    Kubernetes version 0.2+, build 9316edfc0d2b28923fbb6eafa38458350859f926
    $ cluster/kubecfg.sh -server_version
    Server: Kubernetes version 0.2, build a0abb38157
    $ cluster/kubecfg.sh -version=raw
    version.Info{Major:"0", Minor:"2+", GitVersion:"v0.2-25-g9316edfc0d2b28", GitCommit:"9316edfc0d2b28923fbb6eafa38458350859f926", GitTreeState:"clean"}
    $ cluster/kubecfg.sh -server_version=raw
    version.Info{Major:"0", Minor:"2", GitVersion:"v0.2", GitCommit:"a0abb3815755d6a77eed2d07bb0aa7d255e4e769", GitTreeState:"clean"}

Fixes: #1092

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
pull/6/head
Filipe Brandenburger 2014-09-09 14:28:43 -07:00
parent ffcfdd0e2d
commit b849d65b32
1 changed files with 9 additions and 4 deletions

View File

@ -39,7 +39,7 @@ import (
)
var (
serverVersion = flag.Bool("server_version", false, "Print the server's version number.")
serverVersion = verflag.Version("server_version", verflag.VersionFalse, "Print the server's version information and quit")
preventSkew = flag.Bool("expect_version_match", false, "Fail if server's version doesn't match own version.")
httpServer = flag.String("h", "", "The host to connect to.")
config = flag.String("c", "", "Path to the config file.")
@ -152,14 +152,19 @@ func main() {
}
}
if *serverVersion {
if *serverVersion != verflag.VersionFalse {
got, err := kubeClient.ServerVersion()
if err != nil {
fmt.Printf("Couldn't read version from server: %v\n", err)
os.Exit(1)
}
fmt.Printf("Server Version: %#v\n", got)
os.Exit(0)
if *serverVersion == verflag.VersionRaw {
fmt.Printf("%#v\n", *got)
os.Exit(0)
} else {
fmt.Printf("Server: Kubernetes %s\n", got)
os.Exit(0)
}
}
if *preventSkew {