Skip to content

Commit

Permalink
Implement support for global default.yaml and override.yaml configs
Browse files Browse the repository at this point in the history
Stored inside the _config directory, they provide defaults for all
instances stored under the same LIMA_HOME. Settings from override.yaml
take precedence over the instance settings themselves.

Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed Dec 10, 2021
1 parent c0b69c3 commit 213d22a
Show file tree
Hide file tree
Showing 14 changed files with 709 additions and 69 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/diskfs/go-diskfs v1.2.0
github.com/docker/go-units v0.4.0
github.com/elastic/go-libaudit/v2 v2.2.0
github.com/google/go-cmp v0.5.5
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-multierror v1.1.1
github.com/lima-vm/sshocker v0.2.2
Expand All @@ -24,6 +25,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/xorcare/pointer v1.1.0
github.com/yalue/native_endian v1.0.2
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -36,7 +38,6 @@ require (
github.com/fatih/color v1.10.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
Expand All @@ -53,6 +54,7 @@ require (
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.39.0-dev.0.20210518002758-2713b77e8526 // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xorcare/pointer v1.1.0 h1:sFwXOhRF8QZ0tyVZrtxWGIoVZNEmRzBCaFWdONPQIUM=
github.com/xorcare/pointer v1.1.0/go.mod h1:6KLhkOh6YbuvZkT4YbxIbR/wzLBjyMxOiNzZhJTor2Y=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yalue/native_endian v1.0.2 h1:e4SxBbaCoOOO4E3axd7FSriUhzc1bIzqZGG5jl6Evbg=
github.com/yalue/native_endian v1.0.2/go.mod h1:cr+I2WnCwDkkPV0DvgBpGQkJV12CDWR5bAoMtT+56iE=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
}
}

if guestAgentBinary, err := GuestAgentBinary(y.Arch); err != nil {
if guestAgentBinary, err := GuestAgentBinary(*y.Arch); err != nil {
return err
} else {
defer guestAgentBinary.Close()
Expand Down
6 changes: 3 additions & 3 deletions pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
}

func determineSSHLocalPort(y *limayaml.LimaYAML, instName string) (int, error) {
if y.SSH.LocalPort > 0 {
return y.SSH.LocalPort, nil
if *y.SSH.LocalPort > 0 {
return *y.SSH.LocalPort, nil
}
if y.SSH.LocalPort < 0 {
if *y.SSH.LocalPort < 0 {
return 0, fmt.Errorf("invalid ssh local port %d", y.SSH.LocalPort)
}
switch instName {
Expand Down
40 changes: 40 additions & 0 deletions pkg/limayaml/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,46 @@ useHostResolver: true
# - 1.1.1.1
# - 1.0.0.1

# ===================================================================== #
# GLOBAL DEFAULTS AND OVERRIDES
# ===================================================================== #

# The builtin defaults can be changed globally by creating a $LIMA_HOME/_config/default.yaml
# file. It will be used by ALL instances under the same $LIMA_HOME, and it
# will be applied on each `limactl start`, so can affect instance restarts.

# A similar mechanism is $LIMA_HOME/_config/override.yaml, which will take
# precedence even over the settings in an instances lima.yaml file.
# It too applies to ALL instances under the same $LIMA_HOME, and is applied
# on each restart. It can be used to globally override settings, e.g. make
# the mount of the home directory writable.

# On each instance start the config settings are determined: If a value is
# not set in `lima.yaml`, then the `default.yaml` is used. If that file
# doesn't exist, or the value is not defined in the file, then the buildin
# default is used. If `override.yaml` exists and defines the value, then
# it overrides whatever has been choosen so far.

# For slices (e.g. `mounts`, `provision`) and maps (`env`) the entries are
# combined instead of replacing each other. Slices are produced from override
# settings, followed by lima.yaml, followed by defaults.yaml (but NOT from
# builtin defaults). Maps are produced starting with defaults.yaml values,
# overwriting with lima.yaml ones, overwriting with override.yaml.

# Exceptions:
# - `dns` will use the list from the highest priority file; they are not
# combined. If override.yaml defines a list of `dns` entries, then the
# settings in default.yaml and lima.yaml are ignored.
#
# - `mounts` will update the `writable` setting when 2 entries have the
# same `location` value. For this reason they are processed in the opposite
# order: starting with default, followed by lima, and then override.
#
# -`networks` will replace lower priority entries with the same `interface`
# name with higher priority definitions. This does not apply if the
# `interface` field is empty. `networks` are therefore also processed
# in lowest to highest priority order.

# ===================================================================== #
# END OF TEMPLATE
# ===================================================================== #
Loading

0 comments on commit 213d22a

Please sign in to comment.