diff --git a/cmd/minikube/cmd/version.go b/cmd/minikube/cmd/version.go index 3ea5341acb81..77169ae0c76b 100644 --- a/cmd/minikube/cmd/version.go +++ b/cmd/minikube/cmd/version.go @@ -18,18 +18,23 @@ package cmd import ( "encoding/json" + "os/exec" + "strings" "github.com/spf13/cobra" "gopkg.in/yaml.v2" + "k8s.io/klog/v2" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/mustload" "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/reason" "k8s.io/minikube/pkg/version" ) var ( - versionOutput string - shortVersion bool + versionOutput string + shortVersion bool + listPackagesVersions bool ) var versionCmd = &cobra.Command{ @@ -43,6 +48,39 @@ var versionCmd = &cobra.Command{ "minikubeVersion": minikubeVersion, "commit": gitCommitID, } + + if listPackagesVersions { + co := mustload.Running(ClusterFlagValue()) + runner := co.CP.Runner + // docker version --format='{{.Client.Version}}' + // sudo crictl version + // runc --version + // crio version + // buildctl --version + // sudo ctr version + // sudo podman version + + versionCMDS := map[string]*exec.Cmd{ + "docker": exec.Command("docker", "version", "--format={{.Client.Version}}min"), + "crictl": exec.Command("sudo", "crictl", "version"), + "crio": exec.Command("crio", "version"), + "runc": exec.Command("runc", "--version"), + "buildctl": exec.Command("buildctl", "--version"), + "ctr": exec.Command("sudo", "ctr", "version"), + } + for k, v := range versionCMDS { + rr, err := runner.RunCmd(v) + if err != nil { + klog.Warningf("error getting %s's version: %v", k, err) + data[k] = "error" + } else { + data[k] = strings.TrimSpace(rr.Stdout.String()) + } + + } + + } + switch versionOutput { case "": if !shortVersion { @@ -50,6 +88,15 @@ var versionCmd = &cobra.Command{ if gitCommitID != "" { out.Ln("commit: %v", gitCommitID) } + for k, v := range data { + // for backward compatibility we keep the old ways separate + if k == "minikubeVersion" || k == "commit" { + continue + } + if v != "" { + out.Ln("\n%s: %s\n", k, v) + } + } } else { out.Ln("%v", minikubeVersion) } @@ -74,4 +121,5 @@ var versionCmd = &cobra.Command{ func init() { versionCmd.Flags().StringVarP(&versionOutput, "output", "o", "", "One of 'yaml' or 'json'.") versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print just the version number.") + versionCmd.Flags().BoolVar(&listPackagesVersions, "packages", false, "list versions of all packages included with minikube. (cluster must be running)") }