Add some error reporting to the version method
parent
9b2fad5710
commit
112a66c21a
|
@ -479,8 +479,8 @@ func configureRuntimes(h *host.Host, runner bootstrapper.CommandRunner) cruntime
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit.WithError("Failed to enable container runtime", err)
|
exit.WithError("Failed to enable container runtime", err)
|
||||||
}
|
}
|
||||||
version := cr.Version()
|
version, err := cr.Version()
|
||||||
if version != "" {
|
if err == nil {
|
||||||
console.OutStyle(cr.Name(), "Version of container runtime is %s", version)
|
console.OutStyle(cr.Name(), "Version of container runtime is %s", version)
|
||||||
}
|
}
|
||||||
return cr
|
return cr
|
||||||
|
|
|
@ -35,18 +35,18 @@ func (r *Containerd) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version retrieves the current version of this runtime
|
// 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")
|
ver, err := r.Runner.CombinedOutput("containerd --version")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39
|
// containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39
|
||||||
words := strings.Split(ver, " ")
|
words := strings.Split(ver, " ")
|
||||||
if len(words) >= 4 && words[0] == "containerd" {
|
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
|
// SocketPath returns the path to the socket file for containerd
|
||||||
|
|
|
@ -35,16 +35,16 @@ func (r *CRIO) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version retrieves the current version of this runtime
|
// 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")
|
ver, err := r.Runner.CombinedOutput("crio --version")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// crio version 1.13.0
|
// crio version 1.13.0
|
||||||
// commit: ""
|
// commit: ""
|
||||||
line := strings.Split(ver, "\n")[0]
|
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
|
// SocketPath returns the path to the socket file for CRIO
|
||||||
|
|
|
@ -35,7 +35,7 @@ type Manager interface {
|
||||||
// Name is a human readable name for a runtime
|
// Name is a human readable name for a runtime
|
||||||
Name() string
|
Name() string
|
||||||
// Version retrieves the current version of this runtime
|
// Version retrieves the current version of this runtime
|
||||||
Version() string
|
Version() (string, error)
|
||||||
// Enable idempotently enables this runtime on a host
|
// Enable idempotently enables this runtime on a host
|
||||||
Enable() error
|
Enable() error
|
||||||
// Disable idempotently disables this runtime on a host
|
// Disable idempotently disables this runtime on a host
|
||||||
|
|
|
@ -38,14 +38,14 @@ func (r *Docker) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version retrieves the current version of this runtime
|
// 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
|
// Note: the server daemon has to be running, for this call to return successfully
|
||||||
ver, err := r.Runner.CombinedOutput("docker version --format '{{.Server.Version}}'")
|
ver, err := r.Runner.CombinedOutput("docker version --format '{{.Server.Version}}'")
|
||||||
if err != nil {
|
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
|
// SocketPath returns the path to the socket file for Docker
|
||||||
|
|
|
@ -35,16 +35,16 @@ func (r *Rkt) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version retrieves the current version of this runtime
|
// 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")
|
ver, err := r.Runner.CombinedOutput("rkt version")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// rkt Version: 1.24.0
|
// rkt Version: 1.24.0
|
||||||
// appc Version: 0.8.10
|
// appc Version: 0.8.10
|
||||||
line := strings.Split(ver, "\n")[0]
|
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
|
// SocketPath returns the path to the socket file for rkt/rktlet
|
||||||
|
|
Loading…
Reference in New Issue