Merge pull request #20798 from n1hility/fix-user-mode-disable

Fix wsl.conf generation when user-mode-networking is disabled
This commit is contained in:
openshift-merge-bot[bot]
2023-11-29 01:20:12 +00:00
committed by GitHub
2 changed files with 6 additions and 5 deletions

View File

@ -1150,11 +1150,8 @@ func (v *MachineVM) Set(_ string, opts machine.SetOptions) ([]error, error) {
if v.isRunning() { if v.isRunning() {
update = false update = false
setErrors = append(setErrors, fmt.Errorf("user-mode networking can only be changed when the machine is not running")) setErrors = append(setErrors, fmt.Errorf("user-mode networking can only be changed when the machine is not running"))
} } else {
if update && *opts.UserModeNetworking {
dist := toDist(v.Name) dist := toDist(v.Name)
if err := changeDistUserModeNetworking(dist, v.RemoteUsername, v.ImagePath, *opts.UserModeNetworking); err != nil { if err := changeDistUserModeNetworking(dist, v.RemoteUsername, v.ImagePath, *opts.UserModeNetworking); err != nil {
update = false update = false
setErrors = append(setErrors, err) setErrors = append(setErrors, err)

View File

@ -4,6 +4,7 @@
package wsl package wsl
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -320,7 +321,10 @@ func (v *MachineVM) obtainUserModeNetLock() (*fileLock, error) {
func changeDistUserModeNetworking(dist string, user string, image string, enable bool) error { func changeDistUserModeNetworking(dist string, user string, image string, enable bool) error {
// Only install if user-mode is being enabled and there was an image path passed // Only install if user-mode is being enabled and there was an image path passed
if enable && len(image) > 0 { if enable {
if len(image) <= 0 {
return errors.New("existing machine configuration is corrupt, no image is defined")
}
if err := installUserModeDist(dist, image); err != nil { if err := installUserModeDist(dist, image); err != nil {
return err return err
} }