Skip to content

Commit

Permalink
Merge pull request #953 from silvin-lubecki/fix-docker-version-kubern…
Browse files Browse the repository at this point in the history
…etes

Fix Kubernetes duplication in version command
  • Loading branch information
Vincent Demeester authored Mar 23, 2018
2 parents a6d2354 + 54bb5ff commit c3991d0
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions cli/command/system/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ Server:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}{{- end}}
{{- if .KubernetesOK}}{{with .Kubernetes}}
Kubernetes:
Version: {{.Kubernetes}}
Stack API: {{.StackAPI}}
{{- end}}{{end}}`
{{- end}}{{- end}}`

type versionOptions struct {
format string
Expand All @@ -65,9 +60,8 @@ type versionOptions struct {

// versionInfo contains version information of both the Client, and Server
type versionInfo struct {
Client clientVersion
Server *types.Version
Kubernetes *kubernetesVersion
Client clientVersion
Server *types.Version
}

type clientVersion struct {
Expand Down Expand Up @@ -96,10 +90,6 @@ func (v versionInfo) ServerOK() bool {
return v.Server != nil
}

func (v versionInfo) KubernetesOK() bool {
return v.Kubernetes != nil
}

// NewVersionCommand creates a new cobra.Command for `docker version`
func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
var opts versionOptions
Expand Down Expand Up @@ -160,21 +150,27 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
Experimental: dockerCli.ClientInfo().HasExperimental,
Orchestrator: string(dockerCli.ClientInfo().Orchestrator),
},
Kubernetes: getKubernetesVersion(dockerCli, opts.kubeConfig),
}

sv, err := dockerCli.Client().ServerVersion(context.Background())
if err == nil {
vd.Server = &sv
kubeVersion := getKubernetesVersion(dockerCli, opts.kubeConfig)
foundEngine := false
foundKubernetes := false
for _, component := range sv.Components {
if component.Name == "Engine" {
switch component.Name {
case "Engine":
foundEngine = true
buildTime, ok := component.Details["BuildTime"]
if ok {
component.Details["BuildTime"] = reformatDate(buildTime)
}
break
case "Kubernetes":
foundKubernetes = true
if _, ok := component.Details["StackAPI"]; !ok && kubeVersion != nil {
component.Details["StackAPI"] = kubeVersion.StackAPI
}
}
}

Expand All @@ -194,6 +190,15 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
},
})
}
if !foundKubernetes && kubeVersion != nil {
vd.Server.Components = append(vd.Server.Components, types.ComponentVersion{
Name: "Kubernetes",
Version: kubeVersion.Kubernetes,
Details: map[string]string{
"StackAPI": kubeVersion.StackAPI,
},
})
}
}

if err2 := tmpl.Execute(dockerCli.Out(), vd); err2 != nil && err == nil {
Expand Down

0 comments on commit c3991d0

Please sign in to comment.