Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error output of minikube version --components command #12085

Merged
merged 3 commits into from
Aug 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
"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