Skip to content

Commit

Permalink
Merge pull request #12085 from afbjorklund/version-components
Browse files Browse the repository at this point in the history
Fix the error output of minikube version --components command
  • Loading branch information
medyagh authored Aug 6, 2021
2 parents be03223 + 6e571d8 commit 54d16b7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cmd/minikube/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"encoding/json"
"os/exec"
"sort"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,13 +54,14 @@ var versionCmd = &cobra.Command{
co := mustload.Running(ClusterFlagValue())
runner := co.CP.Runner
versionCMDS := map[string]*exec.Cmd{
"docker": exec.Command("docker", "version", "--format={{.Client.Version}}"),
"docker": exec.Command("docker", "--version"),
"dockerd": exec.Command("dockerd", "--version"),
"containerd": exec.Command("containerd", "--version"),
"crio": exec.Command("crio", "version"),
"podman": exec.Command("sudo", "podman", "version"),
"crictl": exec.Command("sudo", "crictl", "version"),
"crio": exec.Command("crio", "--version"),
"podman": exec.Command("sudo", "podman", "--version"),
"crictl": exec.Command("sudo", "crictl", "--version"),
"buildctl": exec.Command("buildctl", "--version"),
"ctr": exec.Command("sudo", "ctr", "version"),
"ctr": exec.Command("ctr", "--version"),
"runc": exec.Command("runc", "--version"),
}
for k, v := range versionCMDS {
Expand All @@ -68,7 +70,10 @@ var versionCmd = &cobra.Command{
klog.Warningf("error getting %s's version: %v", k, err)
data[k] = "error"
} else {
data[k] = strings.TrimSpace(rr.Stdout.String())
version := rr.Stdout.String()
// remove extra lines after the version
version = strings.Split(version, "\n")[0]
data[k] = strings.TrimSpace(version)
}

}
Expand All @@ -82,7 +87,13 @@ var versionCmd = &cobra.Command{
if gitCommitID != "" {
out.Ln("commit: %v", gitCommitID)
}
for k, v := range data {
keys := make([]string, 0, len(data))
for k := range data {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := data[k]
// for backward compatibility we keep displaying the old way for these two
if k == "minikubeVersion" || k == "commit" {
continue
Expand Down

0 comments on commit 54d16b7

Please sign in to comment.