Skip to content

Commit 6ae76d8

Browse files
authored
Merge pull request #436 from rancher-sandbox/default-and-override
Implement support for global default.yaml and override.yaml configs
2 parents 7d3eca5 + 7e24403 commit 6ae76d8

File tree

14 files changed

+709
-69
lines changed

14 files changed

+709
-69
lines changed

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/diskfs/go-diskfs v1.2.0
1414
github.com/docker/go-units v0.4.0
1515
github.com/elastic/go-libaudit/v2 v2.2.0
16+
github.com/google/go-cmp v0.5.5
1617
github.com/gorilla/mux v1.8.0
1718
github.com/hashicorp/go-multierror v1.1.1
1819
github.com/lima-vm/sshocker v0.2.2
@@ -24,6 +25,7 @@ require (
2425
github.com/opencontainers/go-digest v1.0.0
2526
github.com/sirupsen/logrus v1.8.1
2627
github.com/spf13/cobra v1.2.1
28+
github.com/xorcare/pointer v1.1.0
2729
github.com/yalue/native_endian v1.0.2
2830
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7
2931
gopkg.in/yaml.v2 v2.4.0
@@ -36,7 +38,6 @@ require (
3638
github.com/fatih/color v1.10.0 // indirect
3739
github.com/fsnotify/fsnotify v1.4.9 // indirect
3840
github.com/golang/protobuf v1.5.2 // indirect
39-
github.com/google/go-cmp v0.5.5 // indirect
4041
github.com/hashicorp/errwrap v1.0.0 // indirect
4142
github.com/inconshreveable/mousetrap v1.0.0 // indirect
4243
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
@@ -53,6 +54,7 @@ require (
5354
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
5455
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
5556
golang.org/x/text v0.3.6 // indirect
57+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
5658
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
5759
google.golang.org/grpc v1.39.0-dev.0.20210518002758-2713b77e8526 // indirect
5860
google.golang.org/protobuf v1.27.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:
816816
github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
817817
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
818818
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
819+
github.com/xorcare/pointer v1.1.0 h1:sFwXOhRF8QZ0tyVZrtxWGIoVZNEmRzBCaFWdONPQIUM=
820+
github.com/xorcare/pointer v1.1.0/go.mod h1:6KLhkOh6YbuvZkT4YbxIbR/wzLBjyMxOiNzZhJTor2Y=
819821
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
820822
github.com/yalue/native_endian v1.0.2 h1:e4SxBbaCoOOO4E3axd7FSriUhzc1bIzqZGG5jl6Evbg=
821823
github.com/yalue/native_endian v1.0.2/go.mod h1:cr+I2WnCwDkkPV0DvgBpGQkJV12CDWR5bAoMtT+56iE=

pkg/cidata/cidata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
173173
}
174174
}
175175

176-
if guestAgentBinary, err := GuestAgentBinary(y.Arch); err != nil {
176+
if guestAgentBinary, err := GuestAgentBinary(*y.Arch); err != nil {
177177
return err
178178
} else {
179179
defer guestAgentBinary.Close()

pkg/hostagent/hostagent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
156156
}
157157

158158
func determineSSHLocalPort(y *limayaml.LimaYAML, instName string) (int, error) {
159-
if y.SSH.LocalPort > 0 {
160-
return y.SSH.LocalPort, nil
159+
if *y.SSH.LocalPort > 0 {
160+
return *y.SSH.LocalPort, nil
161161
}
162-
if y.SSH.LocalPort < 0 {
162+
if *y.SSH.LocalPort < 0 {
163163
return 0, fmt.Errorf("invalid ssh local port %d", y.SSH.LocalPort)
164164
}
165165
switch instName {

pkg/limayaml/default.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,46 @@ useHostResolver: true
229229
# - 1.1.1.1
230230
# - 1.0.0.1
231231

232+
# ===================================================================== #
233+
# GLOBAL DEFAULTS AND OVERRIDES
234+
# ===================================================================== #
235+
236+
# The builtin defaults can be changed globally by creating a $LIMA_HOME/_config/default.yaml
237+
# file. It will be used by ALL instances under the same $LIMA_HOME, and it
238+
# will be applied on each `limactl start`, so can affect instance restarts.
239+
240+
# A similar mechanism is $LIMA_HOME/_config/override.yaml, which will take
241+
# precedence even over the settings in an instances lima.yaml file.
242+
# It too applies to ALL instances under the same $LIMA_HOME, and is applied
243+
# on each restart. It can be used to globally override settings, e.g. make
244+
# the mount of the home directory writable.
245+
246+
# On each instance start the config settings are determined: If a value is
247+
# not set in `lima.yaml`, then the `default.yaml` is used. If that file
248+
# doesn't exist, or the value is not defined in the file, then the buildin
249+
# default is used. If `override.yaml` exists and defines the value, then
250+
# it overrides whatever has been choosen so far.
251+
252+
# For slices (e.g. `mounts`, `provision`) and maps (`env`) the entries are
253+
# combined instead of replacing each other. Slices are produced from override
254+
# settings, followed by lima.yaml, followed by defaults.yaml (but NOT from
255+
# builtin defaults). Maps are produced starting with defaults.yaml values,
256+
# overwriting with lima.yaml ones, overwriting with override.yaml.
257+
258+
# Exceptions:
259+
# - `dns` will use the list from the highest priority file; they are not
260+
# combined. If override.yaml defines a list of `dns` entries, then the
261+
# settings in default.yaml and lima.yaml are ignored.
262+
#
263+
# - `mounts` will update the `writable` setting when 2 entries have the
264+
# same `location` value. For this reason they are processed in the opposite
265+
# order: starting with default, followed by lima, and then override.
266+
#
267+
# -`networks` will replace lower priority entries with the same `interface`
268+
# name with higher priority definitions. This does not apply if the
269+
# `interface` field is empty. `networks` are therefore also processed
270+
# in lowest to highest priority order.
271+
232272
# ===================================================================== #
233273
# END OF TEMPLATE
234274
# ===================================================================== #

0 commit comments

Comments
 (0)