Skip to content

Commit b883e75

Browse files
authored
Merge pull request #3942 from AkihiroSuda/fix-3914
vzNAT: fix regression
2 parents 26917ea + 7d3d24b commit b883e75

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

pkg/driver/qemu/qemu_driver.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/lima-vm/lima/v2/pkg/networks/usernet"
3737
"github.com/lima-vm/lima/v2/pkg/osutil"
3838
"github.com/lima-vm/lima/v2/pkg/ptr"
39+
"github.com/lima-vm/lima/v2/pkg/reflectutil"
3940
"github.com/lima-vm/lima/v2/pkg/version/versionutil"
4041
)
4142

@@ -97,6 +98,18 @@ func validateConfig(ctx context.Context, cfg *limatype.LimaYAML) error {
9798
return err
9899
}
99100

101+
for i, nw := range cfg.Networks {
102+
if unknown := reflectutil.UnknownNonEmptyFields(nw,
103+
"Lima",
104+
"Socket",
105+
"MACAddress",
106+
"Metric",
107+
"Interface",
108+
); len(unknown) > 0 {
109+
logrus.Warnf("vmType %s: ignoring networks[%d]: %+v", *cfg.VMType, i, unknown)
110+
}
111+
}
112+
100113
if cfg.VMOpts.QEMU.MinimumVersion != nil {
101114
if _, err := semver.NewVersion(*cfg.VMOpts.QEMU.MinimumVersion); err != nil {
102115
return fmt.Errorf("field `vmOpts.qemu.minimumVersion` must be a semvar value, got %q: %w", *cfg.VMOpts.QEMU.MinimumVersion, err)

pkg/driver/vz/vz_driver_darwin.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,25 +238,6 @@ func validateConfig(_ context.Context, cfg *limatype.LimaYAML) error {
238238
); len(unknown) > 0 {
239239
logrus.Warnf("vmType %s: ignoring networks[%d]: %+v", *cfg.VMType, i, unknown)
240240
}
241-
242-
field := fmt.Sprintf("networks[%d]", i)
243-
switch {
244-
case nw.Lima != "":
245-
if nw.VZNAT != nil && *nw.VZNAT {
246-
return fmt.Errorf("field `%s.lima` and field `%s.vzNAT` are mutually exclusive", field, field)
247-
}
248-
case nw.Socket != "":
249-
if nw.VZNAT != nil && *nw.VZNAT {
250-
return fmt.Errorf("field `%s.socket` and field `%s.vzNAT` are mutually exclusive", field, field)
251-
}
252-
case nw.VZNAT != nil && *nw.VZNAT:
253-
if nw.Lima != "" {
254-
return fmt.Errorf("field `%s.vzNAT` and field `%s.lima` are mutually exclusive", field, field)
255-
}
256-
if nw.Socket != "" {
257-
return fmt.Errorf("field `%s.vzNAT` and field `%s.socket` are mutually exclusive", field, field)
258-
}
259-
}
260241
}
261242

262243
switch audioDevice := *cfg.Audio.Device; audioDevice {

pkg/limayaml/validate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,25 @@ func validateNetwork(y *limatype.LimaYAML) error {
449449
if nw.Socket != "" {
450450
errs = errors.Join(errs, fmt.Errorf("field `%s.lima` and field `%s.socket` are mutually exclusive", field, field))
451451
}
452+
if nw.VZNAT != nil && *nw.VZNAT {
453+
errs = errors.Join(errs, fmt.Errorf("field `%s.lima` and field `%s.vzNAT` are mutually exclusive", field, field))
454+
}
452455
case nw.Socket != "":
456+
if nw.VZNAT != nil && *nw.VZNAT {
457+
errs = errors.Join(errs, fmt.Errorf("field `%s.socket` and field `%s.vzNAT` are mutually exclusive", field, field))
458+
}
453459
if fi, err := os.Stat(nw.Socket); err != nil && !errors.Is(err, os.ErrNotExist) {
454460
errs = errors.Join(errs, err)
455461
} else if err == nil && fi.Mode()&os.ModeSocket == 0 {
456462
errs = errors.Join(errs, fmt.Errorf("field `%s.socket` %q points to a non-socket file", field, nw.Socket))
457463
}
464+
case nw.VZNAT != nil && *nw.VZNAT:
465+
if nw.Lima != "" {
466+
errs = errors.Join(errs, fmt.Errorf("field `%s.vzNAT` and field `%s.lima` are mutually exclusive", field, field))
467+
}
468+
if nw.Socket != "" {
469+
errs = errors.Join(errs, fmt.Errorf("field `%s.vzNAT` and field `%s.socket` are mutually exclusive", field, field))
470+
}
458471
default:
459472
errs = errors.Join(errs, fmt.Errorf("field `%s.lima` or field `%s.socket must be set", field, field))
460473
}

0 commit comments

Comments
 (0)