Skip to content

Commit

Permalink
fix: detect WSL for talosctl cluster create on Docker
Browse files Browse the repository at this point in the history
Docker on WSL seems to have same issue as Docker/OS X and
Docker/Windows: container IPs are not routable from the host, so we need
to apply same "magic" by using exposed ports.

WSL `talosctl` binary is built for Linux, so we need to do additional
checks for the platform.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed May 12, 2022
1 parent 166d258 commit c87432f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/provision/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package docker

import (
"bytes"
"context"
"os"
"runtime"

"github.com/docker/docker/client"
Expand Down Expand Up @@ -82,6 +84,12 @@ func (p *provisioner) GetLoadBalancers(networkReq provision.NetworkRequest) (int
switch runtime.GOOS {
case "darwin", "windows":
return "", "127.0.0.1"
case "linux":
if detectWSL() {
return "", "127.0.0.1"
}

fallthrough
default:
return "", ""
}
Expand All @@ -96,3 +104,13 @@ func (p *provisioner) UserDiskName(index int) string {
func (p *provisioner) GetFirstInterface() string {
return "eth0"
}

func detectWSL() bool {
// "Official" way of detecting WSL https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364
contents, err := os.ReadFile("/proc/sys/kernel/osrelease")
if err == nil && (bytes.Contains(contents, []byte("Microsoft")) || bytes.Contains(contents, []byte("WSL"))) {
return true
}

return false
}

0 comments on commit c87432f

Please sign in to comment.