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 #2131 Add preflight check for WSL2 #2323

Merged
merged 1 commit into from
May 11, 2021
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
14 changes: 14 additions & 0 deletions pkg/crc/preflight/preflight_checks_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ const (
minSupportedLibvirtVersion = "3.4.0"
)

func checkRunningInsideWSL2() error {
version, err := ioutil.ReadFile("/proc/version")
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully there are no 'hardened' setups where reading this fail will fail. Wondering if we should ignore this error instead of failing, but probably not.

Copy link
Contributor Author

@gbraad gbraad May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully there are no 'hardened' setups where reading this fail will fail.

You can not run with selinux or apparmor on WSL2. Not sure about other setups... haven't tested. But reading this is a known hardened entry?

Note: There are a lot of limitations, like no systemd, no cgroupsv2 exclusive use, etc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can not run with selinux or apparmor on WSL2.

But this code will run on all linux systems, not just WSL2. I have no idea if it's really blocked in some places, just wondered while reading this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about other setups... haven't tested. But reading this is a known hardened entry?

^^

}

if strings.Contains(string(version), "Microsoft") {
logging.Debugf("Running inside WSL2 environment")
gbraad marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("CodeReady Containers is unsupported using WSL2")
}

return nil
}

func checkVirtualizationEnabled() error {
logging.Debug("Checking if the vmx/svm flags are present in /proc/cpuinfo")
// Check if the cpu flags vmx or svm is present
Expand Down
13 changes: 12 additions & 1 deletion pkg/crc/preflight/preflight_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ var vsockPreflightChecks = Check{
cleanup: removeVsockCrcSettings,
}

var wsl2PreflightChecks = Check{
praveenkumar marked this conversation as resolved.
Show resolved Hide resolved
configKeySuffix: "check-wsl2",
checkDescription: "Checking if running inside WSL2",
check: checkRunningInsideWSL2,
fixDescription: "CodeReady Containers is unsupported using WSL2",
flags: NoFix,
}

const (
vsockUdevSystemRulesPath = "/usr/lib/udev/rules.d/99-crc-vsock.rules"
vsockUdevLocalAdminRulesPath = "/etc/udev/rules.d/99-crc-vsock.rules"
Expand Down Expand Up @@ -220,13 +228,16 @@ func removeVsockCrcSettings() error {
func getAllPreflightChecks() []Check {
usingSystemdResolved := checkSystemdResolvedIsRunning()
checks := getPreflightChecksForDistro(distro(), network.SystemNetworkingMode, usingSystemdResolved == nil)
checks = append(checks, wsl2PreflightChecks)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add this line in individuals getPreflightChecks.

getAllPreflightChecks is used for registering configuration and cleanup. It must includes your check but it won't be run in setup unless you add it in `getPreflightChecks

Copy link
Contributor Author

@gbraad gbraad May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a preflight has become very messy and cumbersome. Too much complexity and variables with no clear meaning have been introduced.

checks = append(checks, vsockPreflightChecks)
return checks
}

func getPreflightChecks(_ bool, _ bool, networkMode network.Mode) []Check {
usingSystemdResolved := checkSystemdResolvedIsRunning()
return getPreflightChecksForDistro(distro(), networkMode, usingSystemdResolved == nil)
checks := getPreflightChecksForDistro(distro(), networkMode, usingSystemdResolved == nil)
checks = append(checks, wsl2PreflightChecks)
return checks
}

func getNetworkChecks(networkMode network.Mode, systemdResolved bool) []Check {
Expand Down