Skip to content

Commit

Permalink
minikube version: new flag --packages to list all included tools vers…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
medyagh committed Jun 24, 2021
1 parent ef0ad82 commit 52f9778
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions cmd/minikube/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -43,13 +48,55 @@ 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 {
out.Ln("minikube version: %v", minikubeVersion)
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)
}
Expand All @@ -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)")
}

0 comments on commit 52f9778

Please sign in to comment.