Skip to content

Commit 6751e39

Browse files
authored
Merge pull request #3833 from afbjorklund/cruntime-version
Cruntime version
2 parents 2b3ad6e + 7d1fdab commit 6751e39

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

cmd/minikube/cmd/start.go

+4
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ func configureRuntimes(h *host.Host, runner bootstrapper.CommandRunner) cruntime
479479
if err != nil {
480480
exit.WithError("Failed to enable container runtime", err)
481481
}
482+
version, err := cr.Version()
483+
if err == nil {
484+
console.OutStyle(cr.Name(), "Version of container runtime is %s", version)
485+
}
482486
return cr
483487
}
484488

pkg/minikube/cruntime/containerd.go

+16
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cruntime
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/golang/glog"
2324
)
@@ -33,6 +34,21 @@ func (r *Containerd) Name() string {
3334
return "containerd"
3435
}
3536

37+
// Version retrieves the current version of this runtime
38+
func (r *Containerd) Version() (string, error) {
39+
ver, err := r.Runner.CombinedOutput("containerd --version")
40+
if err != nil {
41+
return "", err
42+
}
43+
44+
// containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39
45+
words := strings.Split(ver, " ")
46+
if len(words) >= 4 && words[0] == "containerd" {
47+
return strings.Replace(words[2], "v", "", 1), nil
48+
}
49+
return "", fmt.Errorf("unknown version: %q", ver)
50+
}
51+
3652
// SocketPath returns the path to the socket file for containerd
3753
func (r *Containerd) SocketPath() string {
3854
if r.Socket != "" {

pkg/minikube/cruntime/crio.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cruntime
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/golang/glog"
2324
)
@@ -33,6 +34,19 @@ func (r *CRIO) Name() string {
3334
return "CRI-O"
3435
}
3536

37+
// Version retrieves the current version of this runtime
38+
func (r *CRIO) Version() (string, error) {
39+
ver, err := r.Runner.CombinedOutput("crio --version")
40+
if err != nil {
41+
return "", err
42+
}
43+
44+
// crio version 1.13.0
45+
// commit: ""
46+
line := strings.Split(ver, "\n")[0]
47+
return strings.Replace(line, "crio version ", "", 1), nil
48+
}
49+
3650
// SocketPath returns the path to the socket file for CRIO
3751
func (r *CRIO) SocketPath() string {
3852
if r.Socket != "" {

pkg/minikube/cruntime/cruntime.go

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type CommandRunner interface {
3434
type Manager interface {
3535
// Name is a human readable name for a runtime
3636
Name() string
37+
// Version retrieves the current version of this runtime
38+
Version() (string, error)
3739
// Enable idempotently enables this runtime on a host
3840
Enable() error
3941
// Disable idempotently disables this runtime on a host

pkg/minikube/cruntime/cruntime_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ func (f *FakeRunner) CombinedOutput(cmd string) (string, error) {
134134
return f.docker(args, root)
135135
case "crictl":
136136
return f.crictl(args, root)
137+
case "crio":
138+
return f.crio(args, root)
139+
case "containerd":
140+
return f.containerd(args, root)
137141
default:
138142
return "", nil
139143
}
@@ -181,7 +185,29 @@ func (f *FakeRunner) docker(args []string, root bool) (string, error) {
181185
delete(f.containers, id)
182186

183187
}
188+
case "version":
189+
if args[1] == "--format" && args[2] == "'{{.Server.Version}}'" {
190+
return "18.06.2-ce", nil
191+
}
192+
193+
}
194+
return "", nil
195+
}
184196

197+
// crio is a fake implementation of crio
198+
func (f *FakeRunner) crio(args []string, root bool) (string, error) {
199+
switch cmd := args[0]; cmd {
200+
case "--version":
201+
return "crio version 1.13.0", nil
202+
}
203+
return "", nil
204+
}
205+
206+
// containerd is a fake implementation of containerd
207+
func (f *FakeRunner) containerd(args []string, root bool) (string, error) {
208+
switch cmd := args[0]; cmd {
209+
case "--version":
210+
return "containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39", nil
185211
}
186212
return "", nil
187213
}
@@ -284,6 +310,33 @@ func (f *FakeRunner) systemctl(args []string, root bool) (string, error) {
284310
return out, nil
285311
}
286312

313+
func TestVersion(t *testing.T) {
314+
var tests = []struct {
315+
runtime string
316+
want string
317+
}{
318+
{"docker", "18.06.2-ce"},
319+
{"cri-o", "1.13.0"},
320+
{"containerd", "1.2.0"},
321+
}
322+
for _, tc := range tests {
323+
t.Run(tc.runtime, func(t *testing.T) {
324+
runner := NewFakeRunner(t)
325+
r, err := New(Config{Type: tc.runtime, Runner: runner})
326+
if err != nil {
327+
t.Fatalf("New(%s): %v", tc.runtime, err)
328+
}
329+
got, err := r.Version()
330+
if err != nil {
331+
t.Fatalf("Version(%s): %v", tc.runtime, err)
332+
}
333+
if got != tc.want {
334+
t.Errorf("Version(%s) = %q, want: %q", tc.runtime, got, tc.want)
335+
}
336+
})
337+
}
338+
}
339+
287340
// defaultServices reflects the default boot state for the minikube VM
288341
var defaultServices = map[string]serviceState{
289342
"docker": Running,

pkg/minikube/cruntime/docker.go

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ func (r *Docker) Name() string {
3737
return "Docker"
3838
}
3939

40+
// Version retrieves the current version of this runtime
41+
func (r *Docker) Version() (string, error) {
42+
// Note: the server daemon has to be running, for this call to return successfully
43+
ver, err := r.Runner.CombinedOutput("docker version --format '{{.Server.Version}}'")
44+
if err != nil {
45+
return "", err
46+
}
47+
48+
return strings.Split(ver, "\n")[0], nil
49+
}
50+
4051
// SocketPath returns the path to the socket file for Docker
4152
func (r *Docker) SocketPath() string {
4253
return r.Socket

pkg/minikube/cruntime/rkt.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cruntime
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/golang/glog"
2324
)
@@ -33,6 +34,19 @@ func (r *Rkt) Name() string {
3334
return "rkt"
3435
}
3536

37+
// Version retrieves the current version of this runtime
38+
func (r *Rkt) Version() (string, error) {
39+
ver, err := r.Runner.CombinedOutput("rkt version")
40+
if err != nil {
41+
return "", err
42+
}
43+
44+
// rkt Version: 1.24.0
45+
// appc Version: 0.8.10
46+
line := strings.Split(ver, "\n")[0]
47+
return strings.Replace(line, "rkt Version: ", "", 1), nil
48+
}
49+
3650
// SocketPath returns the path to the socket file for rkt/rktlet
3751
func (r *Rkt) SocketPath() string {
3852
if r.Socket != "" {

0 commit comments

Comments
 (0)