Skip to content

Commit f83aa9b

Browse files
committed
Remove VMType check from the lima-init boot script
Do this when setting up the cidata instead, next to the decision on whether to use "cidata" dir or "cidata.iso". This means that this particular boot script is not depending on the driver, but can be used from all container drivers. Signed-off-by: Anders F Björklund <[email protected]>
1 parent 86a7a5a commit f83aa9b

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ LIMA_CIDATA_PLAIN=1
6565
{{- else}}
6666
LIMA_CIDATA_PLAIN=
6767
{{- end}}
68+
{{- if .NoCloudInit}}
69+
LIMA_CIDATA_NO_CLOUD_INIT=1
70+
{{- else}}
71+
LIMA_CIDATA_NO_CLOUD_INIT=
72+
{{- end}}

pkg/cidata/cidata.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGate
118118
return env, nil
119119
}
120120

121+
func useCloudInit(instConfig *limayaml.LimaYAML) bool {
122+
// all drivers but WSL2 use cloud-init
123+
return *instConfig.VMType != limayaml.WSL2
124+
}
125+
121126
func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) {
122127
if err := limayaml.Validate(instConfig, false); err != nil {
123128
return nil, err
@@ -138,12 +143,13 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
138143
Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive},
139144
SlirpNICName: networks.SlirpNICName,
140145

141-
VMType: *instConfig.VMType,
142-
VSockPort: vsockPort,
143-
VirtioPort: virtioPort,
144-
Plain: *instConfig.Plain,
145-
TimeZone: *instConfig.TimeZone,
146-
Param: instConfig.Param,
146+
VMType: *instConfig.VMType,
147+
VSockPort: vsockPort,
148+
VirtioPort: virtioPort,
149+
Plain: *instConfig.Plain,
150+
TimeZone: *instConfig.TimeZone,
151+
NoCloudInit: !useCloudInit(instConfig),
152+
Param: instConfig.Param,
147153
}
148154

149155
if instConfig.VMOpts.VZ.Rosetta.Enabled != nil {
@@ -466,7 +472,7 @@ func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name strin
466472
})
467473
}
468474

469-
if args.VMType == limatype.WSL2 {
475+
if !useCloudInit(instConfig) {
470476
layout = append(layout, iso9660util.Entry{
471477
Path: "ssh_authorized_keys",
472478
Reader: strings.NewReader(strings.Join(args.SSHPubKeys, "\n")),

pkg/cidata/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type TemplateArgs struct {
114114
VirtioPort string
115115
Plain bool
116116
TimeZone string
117+
NoCloudInit bool
117118
}
118119

119120
func ValidateTemplateArgs(args *TemplateArgs) error {

pkg/driver/wsl2/boot/02-wsl2-setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
# This script replaces the cloud-init functionality of creating a user and setting its SSH keys
7-
# when using a WSL2 VM.
8-
[ "$LIMA_CIDATA_VMTYPE" = "wsl2" ] || exit 0
7+
# when cloud-init is not available
8+
[ "$LIMA_CIDATA_NO_CLOUD_INIT" = "1" ] || exit 0
99

1010
# create user
1111
# shellcheck disable=SC2153

0 commit comments

Comments
 (0)