Merge pull request #953 from silvin-lubecki/fix-docker-version-kubernetes

Fix Kubernetes duplication in version command
This commit is contained in:
Vincent Demeester 2018-03-23 15:59:37 +01:00 committed by GitHub
commit c3991d0673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 16 deletions

View File

@ -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
@ -67,7 +62,6 @@ type versionOptions struct {
type versionInfo struct {
Client clientVersion
Server *types.Version
Kubernetes *kubernetesVersion
}
type clientVersion struct {
@ -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
@ -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
}
}
}
@ -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 {