-
Notifications
You must be signed in to change notification settings - Fork 699
Convert limatype.VMOpts to an abstract map #3899
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
base: master
Are you sure you want to change the base?
Conversation
@unsuman here is a way to convert the VMType into an abstract "struct" -type VMOpts struct {
- QEMU QEMUOpts `yaml:"qemu,omitempty" json:"qemu,omitempty"`
-}
+type VMOpts map[VMType]any Then converting/casting is done, by marshalling to YAML and unmarshalling |
In this way, the drivers can provide their specific settings without changes needed in the main codebase. Thanks, this looks clean and adaptable! |
42436c4
to
e68bff0
Compare
I just remembered that the Kubernetes community has been going back and forth about whether user data strings should be encoded as maps, or as list with a If we were following this convention (and I'm not sure we should, but wanted to at least bring it up), then vmOpts:
- name: qemu
value:
qemuOption1: ...
- name: vz
value:
vzOption1: ... Personally I'm not fond of this because it makes jq/yq expressions more complicated, but I do understand the argument that this makes it clearer which keys are struct fields, and which are user supplied list entries. Update
|
I have only seen that (list) as a workaround for ordered maps. vmOpts: !!omap
- qemu:
# Minimum version of QEMU required to create an instance of this template.
# Will be ignored if the vmType is not "qemu"
# 🟢 Builtin default: not set
minimumVersion: null
# Specify desired QEMU CPU type for each arch.
# You can see what options are available for host emulation with: `qemu-system-$(arch) -cpu help`.
# Setting of instructions is supported like this: "qemu64,+ssse3".
# 🟢 Builtin default: hard-coded arch map with type (see the output of `limactl info | jq .defaultTemplate.cpuType`)
cpuType:
# aarch64: "max" # (or "host" when running on aarch64 host)
# armv7l: "max" # (or "host" when running on armv7l host)
# riscv64: "max" # (or "host" when running on riscv64 host)
# x86_64: "max" # (or "host" when running on x86_64 host; additional options are appended on Intel Mac)
- vz:
rosetta:
# Enable Rosetta inside the VM; needs `vmType: vz`
# Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
# 🟢 Builtin default: false
enabled: null
# Register rosetta to /proc/sys/fs/binfmt_misc
# 🟢 Builtin default: false
binfmt: null
- docker:
runtime: runq The benefit of not doing something like this here, is that it is backwards-compatible to not do it... I am glad we are not using kyaml here... I don't think we need the ordered maps? Preferrably the vmOpts should look like any other field in the lima.yaml, even if it is now "extendable". |
One annoying quirk of go-yaml is that map[string]any{"bar": string("two"), "foo": uint64(1)} So I changed the unittest to use a static YAML/JSON string, instead of comparing with the `{"foo":1,"bar":"two"}` |
I don't think it is about ordering, it is about the API promise. As I wrote above, I'm not a bug fan of this convention for CLI usability reasons, and I'm fine to use the map with the driver name as the key. It just should be an intentional decision we make. |
When unmarshaling into It is kind of arbitrary which rules you pick. YAML originates from untyped languages (Perl) were type was inferred from the value and could change (transmogrify) at runtime as needed, which is not a good fit for statically typed languages. Unmarshaling into |
Needs to convert VMOpts.VZ as well, and move the validation (and the struct?) to the driver. It might not be possible to move the QEMUOpts and VZOpts yet, but they should be "gone" type QEMUOpts struct {
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty" jsonschema:"nullable"`
CPUType CPUType `yaml:"cpuType,omitempty" json:"cpuType,omitempty" jsonschema:"nullable"`
}
type CPUType = map[Arch]string
type VZOpts struct {
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
}
type Rosetta struct {
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"nullable"`
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty" jsonschema:"nullable"`
} That is, they can stay as deprecated. But eventually the value is known only to the driver. We will probably have to give up on the jsonschema for Opts, and leave that to driver Validate. |
We will go with what "the library" is using... And provide an entry point, for drivers to use:
Then Lima can switch libraries, in a new SDK. |
fdebf9c
to
cc3c2f2
Compare
The format of the VMOpts is known only to the driver, everyone else will see a basic map[string]any or something similar to it. Converting from the abstract format to the actual format is done using YAML, just like it was before when the format was known. Signed-off-by: Anders F Björklund <[email protected]>
cc3c2f2
to
4b9b253
Compare
The format of the VMOpts is known only to the driver, everyone
else will see a basic
map[string]any
or something similar to it.Note: the
string
is the driver type, theany
is the actual OptsConverting from the abstract format to the actual format is done
using YAML, just like it was before when the format was known.
Issue #3506
Note: the use of QEMUOpts is not addressed here, only VMOpts.
There needs to be a follow up, to move the struct into the driver.
Same for VZ.
Depends: