Skip to content

Commit

Permalink
Merge pull request #1687 from tmjd/report-cluster-type
Browse files Browse the repository at this point in the history
Report version and cluster type from datastore in version command
  • Loading branch information
tmjd authored Jul 21, 2017
2 parents dac2623 + 6511e14 commit 4d9109f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LOCAL_USER_ID?=$(shell id -u $$USER)
PACKAGE_NAME?=github.com/projectcalico/calicoctl

LDFLAGS=-ldflags "-X $(PACKAGE_NAME)/calicoctl/commands.VERSION=$(CALICOCTL_VERSION) \
-X $(PACKAGE_NAME)/calicoctl/calicoctl/commands.BUILD_DATE=$(CALICOCTL_BUILD_DATE) \
-X $(PACKAGE_NAME)/calicoctl/commands.BUILD_DATE=$(CALICOCTL_BUILD_DATE) \
-X $(PACKAGE_NAME)/calicoctl/commands.GIT_REVISION=$(CALICOCTL_GIT_REVISION) -s -w"

LIBCALICOGO_PATH?=none
Expand Down
43 changes: 36 additions & 7 deletions calicoctl/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"strings"

"github.com/docopt/docopt-go"
"github.com/projectcalico/calicoctl/calicoctl/commands/clientmgr"
"github.com/projectcalico/calicoctl/calicoctl/commands/constants"
)

var VERSION, BUILD_DATE, GIT_REVISION string
Expand All @@ -31,24 +33,51 @@ func init() {

func Version(args []string) {
doc := `Usage:
calicoctl version
calicoctl version [--config=<CONFIG>]
Options:
-h --help Show this screen.
-h --help Show this screen.
-c --config=<CONFIG> Path to the file containing connection configuration in
YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
Description:
Display the version of calicoctl.
`
arguments, err := docopt.Parse(doc, args, true, "", false, false)
parsedArgs, err := docopt.Parse(doc, args, true, "", false, false)
if err != nil {
fmt.Printf("Invalid option: 'calicoctl %s'. Use flag '--help' to read about a specific subcommand.\n", strings.Join(args, " "))
os.Exit(1)
}
if len(arguments) == 0 {
if len(parsedArgs) == 0 {
return
}

fmt.Println("Version: ", VERSION)
fmt.Println("Build date: ", BUILD_DATE)
fmt.Println("Git commit: ", GIT_REVISION)
fmt.Println("Client Version: ", VERSION)
fmt.Println("Build date: ", BUILD_DATE)
fmt.Println("Git commit: ", GIT_REVISION)

// Load the client config and connect.
cf := parsedArgs["--config"].(string)
client, err := clientmgr.NewClient(cf)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cfg := client.Config()

val, assigned, err := cfg.GetFelixConfig("CalicoVersion", "")
if err != nil {
val = fmt.Sprintf("unknown (%s)", err)
} else if !assigned {
val = "unknown"
}
fmt.Println("Server Version: ", val)
val, assigned, err = cfg.GetFelixConfig("ClusterType", "")
if err != nil {
val = fmt.Sprintf("unknown (%s)", err)
} else if !assigned {
val = "unknown"
}
fmt.Println("Cluster Type: ", val)
}

0 comments on commit 4d9109f

Please sign in to comment.