diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aee0016a397..56ddde2f278 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -613,11 +613,23 @@ jobs: - name: WSL info if: matrix.provider == 'wsl' shell: pwsh + env: + WSL_UTF8: '1' run: | wsl --update wsl --version wsl --status + - name: Uninstall WSL + if: matrix.provider == 'hyperv' + env: + WSL_UTF8: '1' + continue-on-error: true + shell: pwsh + run: | + wsl --uninstall + wsl --status + - name: Configure container policy shell: pwsh run: | diff --git a/pkg/machine/wsl/stubber.go b/pkg/machine/wsl/stubber.go index 606c6fcfbef..b86adf877a7 100644 --- a/pkg/machine/wsl/stubber.go +++ b/pkg/machine/wsl/stubber.go @@ -91,6 +91,9 @@ func (w WSLStubber) PrepareIgnition(_ *vmconfigs.MachineConfig, _ *ignition.Igni } func (w WSLStubber) Exists(name string) (bool, error) { + if !wutil.IsWSLInstalled() { + return false, nil + } return isWSLExist(env.WithPodmanPrefix(name)) } diff --git a/pkg/machine/wsl/wutil/wutil.go b/pkg/machine/wsl/wutil/wutil.go index 69ec64ccccd..d39a8284c85 100644 --- a/pkg/machine/wsl/wutil/wutil.go +++ b/pkg/machine/wsl/wutil/wutil.go @@ -4,6 +4,7 @@ package wutil import ( "bufio" + "errors" "fmt" "io" "os" @@ -52,11 +53,7 @@ func SilentExecCmd(args ...string) *exec.Cmd { func parseWSLStatus() wslStatus { onceStatus.Do(func() { - status = wslStatus{ - installed: false, - vmpFeatureEnabled: false, - wslFeatureEnabled: false, - } + status = wslStatus{} cmd := SilentExecCmd("--status") out, err := cmd.StdoutPipe() cmd.Stderr = nil @@ -66,14 +63,17 @@ func parseWSLStatus() wslStatus { if err = cmd.Start(); err != nil { return } - status = matchOutputLine(out) - - if err := cmd.Wait(); err != nil { - return + err = cmd.Wait() + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { + // If `wsl --status` returns an exit error + // we assume that WSL isn't installed and + // override whatever was returned by + // matchOutputLine() + status = wslStatus{} } }) - return status }