Skip to content

Commit b89e5b6

Browse files
committed
Improve the limayaml and default.yaml syntax
Use empty strings for strings and document all the fields Allow null for pointers and maps with commented out keys Signed-off-by: Anders F Björklund <[email protected]>
1 parent 88c17d3 commit b89e5b6

File tree

2 files changed

+56
-55
lines changed

2 files changed

+56
-55
lines changed

examples/default.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ mounts:
124124
# List of mount types not supported by the kernel of this distro.
125125
# Also used to resolve the default mount type when not explicitly specified.
126126
# 🟢 Builtin default: null
127-
mountTypesUnsupported: null
127+
mountTypesUnsupported:
128+
# - "9p"
128129

129130
# Mount type for above mounts, such as "reverse-sshfs" (from sshocker), "9p" (QEMU’s virtio-9p-pci, aka virtfs),
130131
# or "virtiofs" (experimental on Linux; needs `vmType: vz` on macOS).

pkg/limayaml/limayaml.go

+54-54
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,46 @@ import (
77
)
88

99
type LimaYAML struct {
10-
MinimumLimaVersion *string `yaml:"minimumLimaVersion,omitempty" json:"minimumLimaVersion,omitempty"`
11-
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
10+
MinimumLimaVersion *string `yaml:"minimumLimaVersion,omitempty" json:"minimumLimaVersion,omitempty" jsonschema:"nullable"`
11+
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty" jsonschema:"nullable"`
1212
VMOpts VMOpts `yaml:"vmOpts,omitempty" json:"vmOpts,omitempty"`
13-
OS *OS `yaml:"os,omitempty" json:"os,omitempty"`
14-
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
13+
OS *OS `yaml:"os,omitempty" json:"os,omitempty" jsonschema:"nullable"`
14+
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"nullable"`
1515
Images []Image `yaml:"images" json:"images"` // REQUIRED
16-
CPUType CPUType `yaml:"cpuType,omitempty" json:"cpuType,omitempty"`
17-
CPUs *int `yaml:"cpus,omitempty" json:"cpus,omitempty"`
18-
Memory *string `yaml:"memory,omitempty" json:"memory,omitempty"` // go-units.RAMInBytes
19-
Disk *string `yaml:"disk,omitempty" json:"disk,omitempty"` // go-units.RAMInBytes
20-
AdditionalDisks []Disk `yaml:"additionalDisks,omitempty" json:"additionalDisks,omitempty"`
16+
CPUType CPUType `yaml:"cpuType,omitempty" json:"cpuType,omitempty" jsonschema:"nullable"`
17+
CPUs *int `yaml:"cpus,omitempty" json:"cpus,omitempty" jsonschema:"nullable"`
18+
Memory *string `yaml:"memory,omitempty" json:"memory,omitempty" jsonschema:"nullable"` // go-units.RAMInBytes
19+
Disk *string `yaml:"disk,omitempty" json:"disk,omitempty" jsonschema:"nullable"` // go-units.RAMInBytes
20+
AdditionalDisks []Disk `yaml:"additionalDisks,omitempty" json:"additionalDisks,omitempty" jsonschema:"nullable"`
2121
Mounts []Mount `yaml:"mounts,omitempty" json:"mounts,omitempty"`
22-
MountTypesUnsupported []string `yaml:"mountTypesUnsupported,omitempty" json:"mountTypesUnsupported,omitempty"`
23-
MountType *MountType `yaml:"mountType,omitempty" json:"mountType,omitempty"`
24-
MountInotify *bool `yaml:"mountInotify,omitempty" json:"mountInotify,omitempty"`
22+
MountTypesUnsupported []string `yaml:"mountTypesUnsupported,omitempty" json:"mountTypesUnsupported,omitempty" jsonschema:"nullable"`
23+
MountType *MountType `yaml:"mountType,omitempty" json:"mountType,omitempty" jsonschema:"nullable"`
24+
MountInotify *bool `yaml:"mountInotify,omitempty" json:"mountInotify,omitempty" jsonschema:"nullable"`
2525
SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"` // REQUIRED (FIXME)
2626
Firmware Firmware `yaml:"firmware,omitempty" json:"firmware,omitempty"`
2727
Audio Audio `yaml:"audio,omitempty" json:"audio,omitempty"`
2828
Video Video `yaml:"video,omitempty" json:"video,omitempty"`
2929
Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"`
30-
UpgradePackages *bool `yaml:"upgradePackages,omitempty" json:"upgradePackages,omitempty"`
30+
UpgradePackages *bool `yaml:"upgradePackages,omitempty" json:"upgradePackages,omitempty" jsonschema:"nullable"`
3131
Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"`
32-
GuestInstallPrefix *string `yaml:"guestInstallPrefix,omitempty" json:"guestInstallPrefix,omitempty"`
32+
GuestInstallPrefix *string `yaml:"guestInstallPrefix,omitempty" json:"guestInstallPrefix,omitempty" jsonschema:"nullable"`
3333
Probes []Probe `yaml:"probes,omitempty" json:"probes,omitempty"`
3434
PortForwards []PortForward `yaml:"portForwards,omitempty" json:"portForwards,omitempty"`
3535
CopyToHost []CopyToHost `yaml:"copyToHost,omitempty" json:"copyToHost,omitempty"`
3636
Message string `yaml:"message,omitempty" json:"message,omitempty"`
37-
Networks []Network `yaml:"networks,omitempty" json:"networks,omitempty"`
37+
Networks []Network `yaml:"networks,omitempty" json:"networks,omitempty" jsonschema:"nullable"`
3838
// `network` was deprecated in Lima v0.7.0, removed in Lima v0.14.0. Use `networks` instead.
3939
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
4040
Param map[string]string `yaml:"param,omitempty" json:"param,omitempty"`
4141
DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"`
4242
HostResolver HostResolver `yaml:"hostResolver,omitempty" json:"hostResolver,omitempty"`
4343
// `useHostResolver` was deprecated in Lima v0.8.1, removed in Lima v0.14.0. Use `hostResolver.enabled` instead.
44-
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
44+
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty" jsonschema:"nullable"`
4545
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
4646
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
47-
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
48-
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty"`
49-
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty"`
47+
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty" jsonschema:"nullable"`
48+
TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty" jsonschema:"nullable"`
49+
NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty" jsonschema:"nullable"`
5050
}
5151

5252
type (
@@ -81,12 +81,12 @@ type VMOpts struct {
8181
}
8282

8383
type QEMUOpts struct {
84-
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty"`
84+
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty" jsonschema:"nullable"`
8585
}
8686

8787
type Rosetta struct {
88-
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
89-
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty"`
88+
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"nullable"`
89+
BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty" jsonschema:"nullable"`
9090
}
9191

9292
type File struct {
@@ -121,7 +121,7 @@ type Disk struct {
121121
type Mount struct {
122122
Location string `yaml:"location" json:"location"` // REQUIRED
123123
MountPoint string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty"`
124-
Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty"`
124+
Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty" jsonschema:"nullable"`
125125
SSHFS SSHFS `yaml:"sshfs,omitempty" json:"sshfs,omitempty"`
126126
NineP NineP `yaml:"9p,omitempty" json:"9p,omitempty"`
127127
Virtiofs Virtiofs `yaml:"virtiofs,omitempty" json:"virtiofs,omitempty"`
@@ -135,36 +135,36 @@ const (
135135
)
136136

137137
type SSHFS struct {
138-
Cache *bool `yaml:"cache,omitempty" json:"cache,omitempty"`
139-
FollowSymlinks *bool `yaml:"followSymlinks,omitempty" json:"followSymlinks,omitempty"`
140-
SFTPDriver *SFTPDriver `yaml:"sftpDriver,omitempty" json:"sftpDriver,omitempty"`
138+
Cache *bool `yaml:"cache,omitempty" json:"cache,omitempty" jsonschema:"nullable"`
139+
FollowSymlinks *bool `yaml:"followSymlinks,omitempty" json:"followSymlinks,omitempty" jsonschema:"nullable"`
140+
SFTPDriver *SFTPDriver `yaml:"sftpDriver,omitempty" json:"sftpDriver,omitempty" jsonschema:"nullable"`
141141
}
142142

143143
type NineP struct {
144-
SecurityModel *string `yaml:"securityModel,omitempty" json:"securityModel,omitempty"`
145-
ProtocolVersion *string `yaml:"protocolVersion,omitempty" json:"protocolVersion,omitempty"`
146-
Msize *string `yaml:"msize,omitempty" json:"msize,omitempty"`
147-
Cache *string `yaml:"cache,omitempty" json:"cache,omitempty"`
144+
SecurityModel *string `yaml:"securityModel,omitempty" json:"securityModel,omitempty" jsonschema:"nullable"`
145+
ProtocolVersion *string `yaml:"protocolVersion,omitempty" json:"protocolVersion,omitempty" jsonschema:"nullable"`
146+
Msize *string `yaml:"msize,omitempty" json:"msize,omitempty" jsonschema:"nullable"`
147+
Cache *string `yaml:"cache,omitempty" json:"cache,omitempty" jsonschema:"nullable"`
148148
}
149149

150150
type Virtiofs struct {
151151
QueueSize *int `yaml:"queueSize,omitempty" json:"queueSize,omitempty"`
152152
}
153153

154154
type SSH struct {
155-
LocalPort *int `yaml:"localPort,omitempty" json:"localPort,omitempty"`
155+
LocalPort *int `yaml:"localPort,omitempty" json:"localPort,omitempty" jsonschema:"nullable"`
156156

157157
// LoadDotSSHPubKeys loads ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
158-
LoadDotSSHPubKeys *bool `yaml:"loadDotSSHPubKeys,omitempty" json:"loadDotSSHPubKeys,omitempty"` // default: false
159-
ForwardAgent *bool `yaml:"forwardAgent,omitempty" json:"forwardAgent,omitempty"` // default: false
160-
ForwardX11 *bool `yaml:"forwardX11,omitempty" json:"forwardX11,omitempty"` // default: false
161-
ForwardX11Trusted *bool `yaml:"forwardX11Trusted,omitempty" json:"forwardX11Trusted,omitempty"` // default: false
158+
LoadDotSSHPubKeys *bool `yaml:"loadDotSSHPubKeys,omitempty" json:"loadDotSSHPubKeys,omitempty" jsonschema:"nullable"` // default: false
159+
ForwardAgent *bool `yaml:"forwardAgent,omitempty" json:"forwardAgent,omitempty" jsonschema:"nullable"` // default: false
160+
ForwardX11 *bool `yaml:"forwardX11,omitempty" json:"forwardX11,omitempty" jsonschema:"nullable"` // default: false
161+
ForwardX11Trusted *bool `yaml:"forwardX11Trusted,omitempty" json:"forwardX11Trusted,omitempty" jsonschema:"nullable"` // default: false
162162
}
163163

164164
type Firmware struct {
165165
// LegacyBIOS disables UEFI if set.
166166
// LegacyBIOS is ignored for aarch64.
167-
LegacyBIOS *bool `yaml:"legacyBIOS,omitempty" json:"legacyBIOS,omitempty"`
167+
LegacyBIOS *bool `yaml:"legacyBIOS,omitempty" json:"legacyBIOS,omitempty" jsonschema:"nullable"`
168168

169169
// Images specify UEFI images (edk2-aarch64-code.fd.gz).
170170
// Defaults to built-in UEFI.
@@ -173,17 +173,17 @@ type Firmware struct {
173173

174174
type Audio struct {
175175
// Device is a QEMU audiodev string
176-
Device *string `yaml:"device,omitempty" json:"device,omitempty"`
176+
Device *string `yaml:"device,omitempty" json:"device,omitempty" jsonschema:"nullable"`
177177
}
178178

179179
type VNCOptions struct {
180-
Display *string `yaml:"display,omitempty" json:"display,omitempty"`
180+
Display *string `yaml:"display,omitempty" json:"display,omitempty" jsonschema:"nullable"`
181181
}
182182

183183
type Video struct {
184184
// Display is a QEMU display string
185-
Display *string `yaml:"display,omitempty" json:"display,omitempty"`
186-
VNC VNCOptions `yaml:"vnc" json:"vnc"`
185+
Display *string `yaml:"display,omitempty" json:"display,omitempty" jsonschema:"nullable"`
186+
VNC VNCOptions `yaml:"vnc,omitempty" json:"vnc,omitempty"`
187187
}
188188

189189
type ProvisionMode = string
@@ -197,16 +197,16 @@ const (
197197
)
198198

199199
type Provision struct {
200-
Mode ProvisionMode `yaml:"mode" json:"mode"` // default: "system"
200+
Mode ProvisionMode `yaml:"mode,omitempty" json:"mode,omitempty" jsonschema:"default=system"`
201201
SkipDefaultDependencyResolution *bool `yaml:"skipDefaultDependencyResolution,omitempty" json:"skipDefaultDependencyResolution,omitempty"`
202202
Script string `yaml:"script" json:"script"`
203203
Playbook string `yaml:"playbook,omitempty" json:"playbook,omitempty"`
204204
}
205205

206206
type Containerd struct {
207-
System *bool `yaml:"system,omitempty" json:"system,omitempty"` // default: false
208-
User *bool `yaml:"user,omitempty" json:"user,omitempty"` // default: true
209-
Archives []File `yaml:"archives,omitempty" json:"archives,omitempty"` // default: see defaultContainerdArchives
207+
System *bool `yaml:"system,omitempty" json:"system,omitempty" jsonschema:"nullable"` // default: false
208+
User *bool `yaml:"user,omitempty" json:"user,omitempty" jsonschema:"nullable"` // default: true
209+
Archives []File `yaml:"archives,omitempty" json:"archives,omitempty"` // default: see defaultContainerdArchives
210210
}
211211

212212
type ProbeMode = string
@@ -216,10 +216,10 @@ const (
216216
)
217217

218218
type Probe struct {
219-
Mode ProbeMode // default: "readiness"
220-
Description string
221-
Script string
222-
Hint string
219+
Mode ProbeMode `yaml:"mode,omitempty" json:"mode,omitempty" jsonschema:"default=readiness"`
220+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
221+
Script string `yaml:"script,omitempty" json:"script,omitempty"`
222+
Hint string `yaml:"hint,omitempty" json:"hint,omitempty"`
223223
}
224224

225225
type Proto = string
@@ -264,13 +264,13 @@ type Network struct {
264264
}
265265

266266
type HostResolver struct {
267-
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
268-
IPv6 *bool `yaml:"ipv6,omitempty" json:"ipv6,omitempty"`
269-
Hosts map[string]string `yaml:"hosts,omitempty" json:"hosts,omitempty"`
267+
Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"nullable"`
268+
IPv6 *bool `yaml:"ipv6,omitempty" json:"ipv6,omitempty" jsonschema:"nullable"`
269+
Hosts map[string]string `yaml:"hosts,omitempty" json:"hosts,omitempty" jsonschema:"nullable"`
270270
}
271271

272272
type CACertificates struct {
273-
RemoveDefaults *bool `yaml:"removeDefaults,omitempty" json:"removeDefaults,omitempty"` // default: false
274-
Files []string `yaml:"files,omitempty" json:"files,omitempty"`
275-
Certs []string `yaml:"certs,omitempty" json:"certs,omitempty"`
273+
RemoveDefaults *bool `yaml:"removeDefaults,omitempty" json:"removeDefaults,omitempty" jsonschema:"nullable"` // default: false
274+
Files []string `yaml:"files,omitempty" json:"files,omitempty" jsonschema:"nullable"`
275+
Certs []string `yaml:"certs,omitempty" json:"certs,omitempty" jsonschema:"nullable"`
276276
}

0 commit comments

Comments
 (0)