mirror of https://github.com/docker/cli.git
Fix Kubernetes duplication in version command when the server already exposes one Kubernetes component
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This commit is contained in:
parent
a6d235430a
commit
54bb5ffeca
|
@ -51,12 +51,7 @@ Server:{{if ne .Platform.Name ""}} {{.Platform.Name}}{{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end}}{{- end}}
|
{{- end}}{{- end}}`
|
||||||
{{- if .KubernetesOK}}{{with .Kubernetes}}
|
|
||||||
Kubernetes:
|
|
||||||
Version: {{.Kubernetes}}
|
|
||||||
Stack API: {{.StackAPI}}
|
|
||||||
{{- end}}{{end}}`
|
|
||||||
|
|
||||||
type versionOptions struct {
|
type versionOptions struct {
|
||||||
format string
|
format string
|
||||||
|
@ -67,7 +62,6 @@ type versionOptions struct {
|
||||||
type versionInfo struct {
|
type versionInfo struct {
|
||||||
Client clientVersion
|
Client clientVersion
|
||||||
Server *types.Version
|
Server *types.Version
|
||||||
Kubernetes *kubernetesVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientVersion struct {
|
type clientVersion struct {
|
||||||
|
@ -96,10 +90,6 @@ func (v versionInfo) ServerOK() bool {
|
||||||
return v.Server != nil
|
return v.Server != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v versionInfo) KubernetesOK() bool {
|
|
||||||
return v.Kubernetes != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewVersionCommand creates a new cobra.Command for `docker version`
|
// NewVersionCommand creates a new cobra.Command for `docker version`
|
||||||
func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
|
func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
var opts versionOptions
|
var opts versionOptions
|
||||||
|
@ -160,21 +150,27 @@ func runVersion(dockerCli command.Cli, opts *versionOptions) error {
|
||||||
Experimental: dockerCli.ClientInfo().HasExperimental,
|
Experimental: dockerCli.ClientInfo().HasExperimental,
|
||||||
Orchestrator: string(dockerCli.ClientInfo().Orchestrator),
|
Orchestrator: string(dockerCli.ClientInfo().Orchestrator),
|
||||||
},
|
},
|
||||||
Kubernetes: getKubernetesVersion(dockerCli, opts.kubeConfig),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sv, err := dockerCli.Client().ServerVersion(context.Background())
|
sv, err := dockerCli.Client().ServerVersion(context.Background())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
vd.Server = &sv
|
vd.Server = &sv
|
||||||
|
kubeVersion := getKubernetesVersion(dockerCli, opts.kubeConfig)
|
||||||
foundEngine := false
|
foundEngine := false
|
||||||
|
foundKubernetes := false
|
||||||
for _, component := range sv.Components {
|
for _, component := range sv.Components {
|
||||||
if component.Name == "Engine" {
|
switch component.Name {
|
||||||
|
case "Engine":
|
||||||
foundEngine = true
|
foundEngine = true
|
||||||
buildTime, ok := component.Details["BuildTime"]
|
buildTime, ok := component.Details["BuildTime"]
|
||||||
if ok {
|
if ok {
|
||||||
component.Details["BuildTime"] = reformatDate(buildTime)
|
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 {
|
if err2 := tmpl.Execute(dockerCli.Out(), vd); err2 != nil && err == nil {
|
||||||
|
|
Loading…
Reference in New Issue