Skip to content

Commit

Permalink
Add the used Kubernetes Version to kudo version output (#1671)
Browse files Browse the repository at this point in the history
* Add the used kubernetes client version to version output

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
  • Loading branch information
ANeumann82 committed Sep 9, 2020
1 parent 6b1daee commit 6fda0fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
14 changes: 8 additions & 6 deletions pkg/kudoctl/cmd/diagnostics/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ builddate: "1970-01-01T00:00:00Z"
goversion: go1.13.4
compiler: gc
platform: linux/amd64
kubernetesclientversion: v0.18.6
`
)

Expand Down Expand Up @@ -322,12 +323,13 @@ func TestPrinter_printYaml(t *testing.T) {
{
desc: "print Yaml OK",
v: version.Info{
GitVersion: "dev",
GitCommit: "dev",
BuildDate: "1970-01-01T00:00:00Z",
GoVersion: "go1.13.4",
Compiler: "gc",
Platform: "linux/amd64",
GitVersion: "dev",
GitCommit: "dev",
BuildDate: "1970-01-01T00:00:00Z",
GoVersion: "go1.13.4",
Compiler: "gc",
Platform: "linux/amd64",
KubernetesClientVersion: "v0.18.6",
},
parentDir: "root",
name: "version",
Expand Down
26 changes: 19 additions & 7 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import (
"fmt"
"os"
"runtime"
"runtime/debug"
"strings"

"github.com/Masterminds/semver/v3"
)

// Info contains versioning information.
type Info struct {
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
KubernetesClientVersion string `json:"kubernetesClientVersion"`
}

// String returns info as a human-friendly version string.
Expand All @@ -41,14 +43,24 @@ func Get() Info {
gitCommit = "dev"
}

return Info{
result := Info{
GitVersion: gitVersion,
GitCommit: gitCommit,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}

if info, ok := debug.ReadBuildInfo(); ok {
for _, dep := range info.Deps {
if dep.Path == "k8s.io/client-go" {
result.KubernetesClientVersion = dep.Version
}
}
}

return result
}

// Version is an extension of semver.Version
Expand Down

0 comments on commit 6fda0fa

Please sign in to comment.