Skip to content

Commit 2a2c84e

Browse files
committed
Add minimumLimaVersion and minimumQEMUVersion fields to lima.yaml
This will allow us to specify the requirements in the templates not just in a comment, but in a way that can be validated. Signed-off-by: Jan Dubois <[email protected]>
1 parent cd12dbe commit 2a2c84e

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

examples/default.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
# Default values in this YAML file are specified by `null` instead of Lima's "builtin default" values,
66
# so they can be overridden by the $LIMA_HOME/_config/default.yaml mechanism documented at the end of this file.
77

8+
# A template should specify the minimum Lima version required to parse this template correctly.
9+
# It should not be set if the minimum version is less than 1.0.0
10+
# 🟢 Builtin default: not set
11+
minimumLimaVersion: null
12+
13+
# Minimum version of QEMU required to create an instance of this template.
14+
# Will be ignored if the vmType is not "qemu"
15+
# 🟢 Builtin default: not set
16+
minimumQEMUVersion: null
17+
818
# VM type: "qemu", "vz" (on macOS 13 and later), or "default".
919
# The vmType can be specified only on creating the instance.
1020
# The vmType of existing instances cannot be changed.

pkg/limayaml/limayaml.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
type LimaYAML struct {
10+
MinimumLimaVersion *string `yaml:"minimumLimaVersion" json:"minimumLimaVersion,omitempty"`
11+
MinimumQEMUVersion *string `yaml:"minimumQEMUVersion" json:"minimumQEMUVersion,omitempty"`
1012
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
1113
OS *OS `yaml:"os,omitempty" json:"os,omitempty"`
1214
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`

pkg/limayaml/validate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"strings"
1313
"unicode"
1414

15+
"github.com/coreos/go-semver/semver"
1516
"github.com/docker/go-units"
1617
"github.com/lima-vm/lima/pkg/localpathutil"
1718
"github.com/lima-vm/lima/pkg/networks"
1819
"github.com/lima-vm/lima/pkg/osutil"
20+
"github.com/lima-vm/lima/pkg/version"
21+
"github.com/lima-vm/lima/pkg/version/versionutil"
1922
"github.com/sirupsen/logrus"
2023
)
2124

@@ -43,6 +46,23 @@ func validateFileObject(f File, fieldName string) error {
4346
}
4447

4548
func Validate(y *LimaYAML, warn bool) error {
49+
if y.MinimumLimaVersion != nil {
50+
if _, err := versionutil.Parse(*y.MinimumLimaVersion); err != nil {
51+
return fmt.Errorf("field `minimumLimaVersion` must be a semvar value, got %q: %w", *y.MinimumLimaVersion, err)
52+
}
53+
limaVersion, err := versionutil.Parse(version.Version)
54+
if err != nil {
55+
return fmt.Errorf("can't parse builtin Lima version %q: %w", version.Version, err)
56+
}
57+
if versionutil.GreaterThan(*y.MinimumLimaVersion, limaVersion.String()) {
58+
return fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, limaVersion.String())
59+
}
60+
}
61+
if y.MinimumQEMUVersion != nil {
62+
if _, err := semver.NewVersion(*y.MinimumQEMUVersion); err != nil {
63+
return fmt.Errorf("field `minimumQEMUVersion` must be a semvar value, got %q: %w", *y.MinimumLimaVersion, err)
64+
}
65+
}
4666
switch *y.OS {
4767
case LINUX:
4868
default:

pkg/qemu/qemu.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
496496
if version.LessThan(*semver.New(MinimumQemuVersion)) {
497497
logrus.Fatalf("QEMU %v is too old, %v or later required", version, MinimumQemuVersion)
498498
}
499+
if y.MinimumQEMUVersion != nil && version.LessThan(*semver.New(*y.MinimumQEMUVersion)) {
500+
logrus.Fatalf("QEMU %v is too old, template requires %q or later", version, *y.MinimumQEMUVersion)
501+
}
499502
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && version.Equal(*semver.New("8.2.0")) {
500503
logrus.Fatal("QEMU 8.2.0 is no longer supported on ARM Mac due to <https://gitlab.com/qemu-project/qemu/-/issues/1990>. " +
501504
"Please upgrade QEMU to v8.2.1 (or downgrade to v8.1.x).")

0 commit comments

Comments
 (0)