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

Check if Docker installed via Snap Package Manager #11088

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 15 additions & 6 deletions pkg/minikube/command/kic_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {
}
klog.Infof("%s (temp): %s --> %s (%d bytes)", k.ociBin, src, dst, f.GetLength())

isSnap := isSnapBinary()
tmpFolder, err := tempDirectory(isSnap)
tmpFolder, err := tempDirectory(isMinikubeSnap(), isDockerSnap())
if err != nil {
return errors.Wrap(err, "determining temp directory")
}
Expand All @@ -207,8 +206,8 @@ func (k *kicRunner) Copy(f assets.CopyableFile) error {

// tempDirectory returns the directory to use as the temp directory
// or an empty string if it should use the os default temp directory.
func tempDirectory(isSnap bool) (string, error) {
if !isSnap {
func tempDirectory(isMinikubeSnap bool, isDockerSnap bool) (string, error) {
if !isMinikubeSnap && !isDockerSnap {
return "", nil
}

Expand All @@ -222,8 +221,8 @@ func tempDirectory(isSnap bool) (string, error) {
return home, nil
}

// isSnapBinary returns true if the binary path includes "snap".
func isSnapBinary() bool {
// isMinikubeSnap returns true if the minikube binary path includes "snap".
func isMinikubeSnap() bool {
spowelljr marked this conversation as resolved.
Show resolved Hide resolved
ex, err := os.Executable()
if err != nil {
return false
Expand All @@ -232,6 +231,16 @@ func isSnapBinary() bool {
return strings.Contains(exPath, "snap")
}

// isDockerSnap returns true if Docker binary path includes "snap".
func isDockerSnap() bool {
c := exec.Command("which", "docker")
o, err := c.Output()
if err != nil {
return false
}
return strings.Contains(string(o), "snap")
}

func (k *kicRunner) copy(src string, dst string) error {
fullDest := fmt.Sprintf("%s:%s", k.nameOrID, dst)
if k.ociBin == oci.Podman {
Expand Down
15 changes: 9 additions & 6 deletions pkg/minikube/command/kic_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ func TestKICRunner(t *testing.T) {
}

tests := []struct {
in bool
want string
isMinikubeSnap bool
isDockerSnap bool
want string
}{
{false, ""},
{true, home},
{false, false, ""},
{true, true, home},
{false, true, home},
{true, false, home},
}

for _, tt := range tests {
got, err := tempDirectory(tt.in)
got, err := tempDirectory(tt.isMinikubeSnap, tt.isDockerSnap)
if err != nil {
t.Fatalf("failed to get temp directory: %v", err)
}

if got != tt.want {
t.Errorf("tempDirectory(%t) = %s; want %s", tt.in, got, tt.want)
t.Errorf("tempDirectory(%t, %t) = %s; want %s", tt.isMinikubeSnap, tt.isDockerSnap, got, tt.want)
}
}
})
Expand Down