Add Version() function to the Manager interface

Helps with troubleshooting container runtimes
pull/3833/head
Anders F Björklund 2019-03-02 19:39:18 +01:00
parent f68b5cb9cc
commit 0c67b60604
5 changed files with 57 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package cruntime
import (
"fmt"
"strings"
"github.com/golang/glog"
)
@ -33,6 +34,21 @@ func (r *Containerd) Name() string {
return "containerd"
}
// Version retrieves the current version of this runtime
func (r *Containerd) Version() string {
ver, err := r.Runner.CombinedOutput("containerd --version")
if err != nil {
return ""
}
// 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 ""
}
// SocketPath returns the path to the socket file for containerd
func (r *Containerd) SocketPath() string {
if r.Socket != "" {

View File

@ -18,6 +18,7 @@ package cruntime
import (
"fmt"
"strings"
"github.com/golang/glog"
)
@ -33,6 +34,19 @@ func (r *CRIO) Name() string {
return "CRI-O"
}
// Version retrieves the current version of this runtime
func (r *CRIO) Version() string {
ver, err := r.Runner.CombinedOutput("crio --version")
if err != nil {
return ""
}
// crio version 1.13.0
// commit: ""
line := strings.Split(ver, "\n")[0]
return strings.Replace(line, "crio version ", "", 1)
}
// SocketPath returns the path to the socket file for CRIO
func (r *CRIO) SocketPath() string {
if r.Socket != "" {

View File

@ -34,6 +34,8 @@ type CommandRunner interface {
type Manager interface {
// Name is a human readable name for a runtime
Name() string
// Version retrieves the current version of this runtime
Version() string
// Enable idempotently enables this runtime on a host
Enable() error
// Disable idempotently disables this runtime on a host

View File

@ -37,6 +37,17 @@ func (r *Docker) Name() string {
return "Docker"
}
// Version retrieves the current version of this runtime
func (r *Docker) Version() string {
// 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 strings.Split(ver, "\n")[0]
}
// SocketPath returns the path to the socket file for Docker
func (r *Docker) SocketPath() string {
return r.Socket

View File

@ -18,6 +18,7 @@ package cruntime
import (
"fmt"
"strings"
"github.com/golang/glog"
)
@ -33,6 +34,19 @@ func (r *Rkt) Name() string {
return "rkt"
}
// Version retrieves the current version of this runtime
func (r *Rkt) Version() string {
ver, err := r.Runner.CombinedOutput("rkt version")
if err != nil {
return ""
}
// rkt Version: 1.24.0
// appc Version: 0.8.10
line := strings.Split(ver, "\n")[0]
return strings.Replace(line, "rkt Version: ", "", 1)
}
// SocketPath returns the path to the socket file for rkt/rktlet
func (r *Rkt) SocketPath() string {
if r.Socket != "" {