diff --git a/pkg/skaffold/docker/client.go b/pkg/skaffold/docker/client.go index 71294c92c6f..9b38463c1c5 100644 --- a/pkg/skaffold/docker/client.go +++ b/pkg/skaffold/docker/client.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "net/http" "os" "os/exec" @@ -164,22 +163,8 @@ func getUserAgentHeader() map[string]string { } } -func detectWsl() (bool, error) { - if _, err := os.Stat("/proc/version"); err == nil { - b, err := ioutil.ReadFile("/proc/version") - if err != nil { - return false, fmt.Errorf("read /proc/version: %w", err) - } - str := strings.ToLower(string(b)) - if strings.Contains(str, "microsoft") { - return true, nil - } - } - return false, nil -} - func getMiniKubeFilename() (string, error) { - if found, _ := detectWsl(); found { + if found, _ := util.DetectWSL(); found { filename, err := exec.LookPath("minikube.exe") if err != nil { return "", errors.New("unable to find minikube.exe. Please add it to PATH environment variable") @@ -221,7 +206,8 @@ func getMinikubeDockerEnv(minikubeProfile string) (map[string]string, error) { env[kv[0]] = kv[1] } - if found, _ := detectWsl(); found { + if found, _ := util.DetectWSL(); found { + // rewrite Unix path to Windows cmd := exec.Command("wslpath", env["DOCKER_CERT_PATH"]) out, err := util.RunCmdOut(cmd) if err == nil { diff --git a/pkg/skaffold/util/wsl.go b/pkg/skaffold/util/wsl.go new file mode 100644 index 00000000000..30f07ba1088 --- /dev/null +++ b/pkg/skaffold/util/wsl.go @@ -0,0 +1,41 @@ +/* +Copyright 2020 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "fmt" + "io/ioutil" + "os" + "strings" +) + +// DetectWSL checks for Windows Subsystem for Linux +func DetectWSL() (bool, error) { + if _, err := os.Stat("/proc/version"); err == nil { + b, err := ioutil.ReadFile("/proc/version") + if err != nil { + return false, fmt.Errorf("read /proc/version: %w", err) + } + + // Microsoft changed the case between WSL1 and WSL2 + str := strings.ToLower(string(b)) + if strings.Contains(str, "microsoft") { + return true, nil + } + } + return false, nil +}