Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of quotes in cruntime format strings #6549

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *CRIO) Disable() error {
// ImageExists checks if an image exists
func (r *CRIO) ImageExists(name string, sha string) bool {
// expected output looks like [NAME@sha256:SHA]
c := exec.Command("sudo", "podman", "inspect", "--format='{{.Id}}'", name)
c := exec.Command("sudo", "podman", "inspect", "--format", "{{.Id}}", name)
rr, err := r.Runner.RunCmd(c)
if err != nil {
return false
Expand Down
61 changes: 59 additions & 2 deletions pkg/minikube/cruntime/cruntime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ func TestName(t *testing.T) {
}
}

func TestImageExists(t *testing.T) {
var tests = []struct {
runtime string
name string
sha string
want bool
}{
{"docker", "missing", "0000000000000000000000000000000000000000000000000000000000000000", false},
{"docker", "image", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", true},
{"crio", "missing", "0000000000000000000000000000000000000000000000000000000000000000", false},
{"crio", "image", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", true},
}
for _, tc := range tests {
t.Run(tc.runtime, func(t *testing.T) {
r, err := New(Config{Type: tc.runtime, Runner: NewFakeRunner(t)})
if err != nil {
t.Fatalf("New(%s): %v", tc.runtime, err)
}

got := r.ImageExists(tc.name, tc.sha)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("ImageExists(%s) returned diff (-want +got):\n%s", tc.runtime, diff)
}
})
}
}

func TestCGroupDriver(t *testing.T) {
var tests = []struct {
runtime string
Expand Down Expand Up @@ -174,6 +201,8 @@ func (f *FakeRunner) RunCmd(cmd *exec.Cmd) (*command.RunResult, error) {
return buffer(f.which(args, root))
case "docker":
return buffer(f.docker(args, root))
case "podman":
return buffer(f.podman(args, root))
case "crictl", "/usr/bin/crictl":
return buffer(f.crictl(args, root))
case "crio":
Expand Down Expand Up @@ -225,19 +254,47 @@ func (f *FakeRunner) docker(args []string, _ bool) (string, error) {
}
case "version":

if args[1] == "--format" && args[2] == "'{{.Server.Version}}'" {
if args[1] == "--format" && args[2] == "{{.Server.Version}}" {
return "18.06.2-ce", nil
}

case "inspect":

if args[1] == "--format" && args[2] == "{{.Id}}" {
if args[3] == "missing" {
return "", &exec.ExitError{Stderr: []byte("Error: No such object: missing")}
}
return "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", nil
}

case "info":

if args[1] == "--format" && args[2] == "'{{.CgroupDriver}}'" {
if args[1] == "--format" && args[2] == "{{.CgroupDriver}}" {
return "cgroupfs", nil
}
}
return "", nil
}

// podman is a fake implementation of podman
func (f *FakeRunner) podman(args []string, _ bool) (string, error) {
switch cmd := args[0]; cmd {
case "--version":
return "podman version 1.6.4", nil

case "inspect":

if args[1] == "--format" && args[2] == "{{.Id}}" {
if args[3] == "missing" {
return "", &exec.ExitError{Stderr: []byte("Error: error getting image \"missing\": unable to find a name and tag match for missing in repotags: no such image")}
}
return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", nil
}

}
return "", nil
}

// crio is a fake implementation of crio
func (f *FakeRunner) crio(args []string, _ bool) (string, error) { //nolint (result 1 (error) is always nil)
if args[0] == "--version" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *Docker) Style() out.StyleEnum {
// Version retrieves the current version of this runtime
func (r *Docker) Version() (string, error) {
// Note: the server daemon has to be running, for this call to return successfully
c := exec.Command("docker", "version", "--format", "'{{.Server.Version}}'")
c := exec.Command("docker", "version", "--format", "{{.Server.Version}}")
rr, err := r.Runner.RunCmd(c)
if err != nil {
return "", err
Expand Down Expand Up @@ -105,7 +105,7 @@ func (r *Docker) Disable() error {
// ImageExists checks if an image exists
func (r *Docker) ImageExists(name string, sha string) bool {
// expected output looks like [SHA_ALGO:SHA]
c := exec.Command("docker", "inspect", "--format='{{.Id}}'", name)
c := exec.Command("docker", "inspect", "--format", "{{.Id}}", name)
rr, err := r.Runner.RunCmd(c)
if err != nil {
return false
Expand All @@ -130,7 +130,7 @@ func (r *Docker) LoadImage(path string) error {
// CGroupDriver returns cgroup driver ("cgroupfs" or "systemd")
func (r *Docker) CGroupDriver() (string, error) {
// Note: the server daemon has to be running, for this call to return successfully
c := exec.Command("docker", "info", "--format", "'{{.CgroupDriver}}'")
c := exec.Command("docker", "info", "--format", "{{.CgroupDriver}}")
rr, err := r.Runner.RunCmd(c)
if err != nil {
return "", err
Expand Down