From 112a66c21ac5f9abbb138d77248854246f4daf54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Sun, 10 Mar 2019 10:18:26 +0100 Subject: [PATCH] Add some error reporting to the version method --- cmd/minikube/cmd/start.go | 4 ++-- pkg/minikube/cruntime/containerd.go | 8 ++++---- pkg/minikube/cruntime/crio.go | 6 +++--- pkg/minikube/cruntime/cruntime.go | 2 +- pkg/minikube/cruntime/docker.go | 6 +++--- pkg/minikube/cruntime/rkt.go | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 1a9481e33d..7080189d86 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -479,8 +479,8 @@ func configureRuntimes(h *host.Host, runner bootstrapper.CommandRunner) cruntime if err != nil { exit.WithError("Failed to enable container runtime", err) } - version := cr.Version() - if version != "" { + version, err := cr.Version() + if err == nil { console.OutStyle(cr.Name(), "Version of container runtime is %s", version) } return cr diff --git a/pkg/minikube/cruntime/containerd.go b/pkg/minikube/cruntime/containerd.go index 4bd4712386..0e4f7a5362 100644 --- a/pkg/minikube/cruntime/containerd.go +++ b/pkg/minikube/cruntime/containerd.go @@ -35,18 +35,18 @@ func (r *Containerd) Name() string { } // Version retrieves the current version of this runtime -func (r *Containerd) Version() string { +func (r *Containerd) Version() (string, error) { ver, err := r.Runner.CombinedOutput("containerd --version") if err != nil { - return "" + return "", err } // containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39 words := strings.Split(ver, " ") if len(words) >= 4 && words[0] == "containerd" { - return strings.Replace(words[2], "v", "", 1) + return strings.Replace(words[2], "v", "", 1), nil } - return "" + return "", fmt.Errorf("unknown version: %q", ver) } // SocketPath returns the path to the socket file for containerd diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 0c5d3bacf1..c3e7a72963 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -35,16 +35,16 @@ func (r *CRIO) Name() string { } // Version retrieves the current version of this runtime -func (r *CRIO) Version() string { +func (r *CRIO) Version() (string, error) { ver, err := r.Runner.CombinedOutput("crio --version") if err != nil { - return "" + return "", err } // crio version 1.13.0 // commit: "" line := strings.Split(ver, "\n")[0] - return strings.Replace(line, "crio version ", "", 1) + return strings.Replace(line, "crio version ", "", 1), nil } // SocketPath returns the path to the socket file for CRIO diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index 3981bed50b..af904c797b 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -35,7 +35,7 @@ type Manager interface { // Name is a human readable name for a runtime Name() string // Version retrieves the current version of this runtime - Version() string + Version() (string, error) // Enable idempotently enables this runtime on a host Enable() error // Disable idempotently disables this runtime on a host diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index 647d77796a..5ba542d65b 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -38,14 +38,14 @@ func (r *Docker) Name() string { } // Version retrieves the current version of this runtime -func (r *Docker) Version() string { +func (r *Docker) Version() (string, error) { // Note: the server daemon has to be running, for this call to return successfully ver, err := r.Runner.CombinedOutput("docker version --format '{{.Server.Version}}'") if err != nil { - return "" + return "", err } - return strings.Split(ver, "\n")[0] + return strings.Split(ver, "\n")[0], nil } // SocketPath returns the path to the socket file for Docker diff --git a/pkg/minikube/cruntime/rkt.go b/pkg/minikube/cruntime/rkt.go index 20e74d9ae6..4e80e67b4e 100644 --- a/pkg/minikube/cruntime/rkt.go +++ b/pkg/minikube/cruntime/rkt.go @@ -35,16 +35,16 @@ func (r *Rkt) Name() string { } // Version retrieves the current version of this runtime -func (r *Rkt) Version() string { +func (r *Rkt) Version() (string, error) { ver, err := r.Runner.CombinedOutput("rkt version") if err != nil { - return "" + return "", err } // rkt Version: 1.24.0 // appc Version: 0.8.10 line := strings.Split(ver, "\n")[0] - return strings.Replace(line, "rkt Version: ", "", 1) + return strings.Replace(line, "rkt Version: ", "", 1), nil } // SocketPath returns the path to the socket file for rkt/rktlet