Skip to content

Commit 94551ef

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 <anders.f.bjorklund@gmail.com>
1 parent 44b65fa commit 94551ef

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh renamed to pkg/cidata/cidata.TEMPLATE.d/boot/02-no-cloud-init.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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ LIMA_CIDATA_PLAIN=1
5959
{{- else}}
6060
LIMA_CIDATA_PLAIN=
6161
{{- end}}
62+
{{- if .NoCloudInit}}
63+
LIMA_CIDATA_NO_CLOUD_INIT=1
64+
{{- else}}
65+
LIMA_CIDATA_NO_CLOUD_INIT=
66+
{{- end}}

pkg/cidata/cidata.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGate
116116
return env, nil
117117
}
118118

119+
func useCloudInit(instConfig *limayaml.LimaYAML) bool {
120+
// all drivers but WSL2 use cloud-init
121+
return *instConfig.VMType != limayaml.WSL2
122+
}
123+
119124
func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) {
120125
if err := limayaml.Validate(instConfig, false); err != nil {
121126
return nil, err
@@ -143,6 +148,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
143148
VirtioPort: virtioPort,
144149
Plain: *instConfig.Plain,
145150
TimeZone: *instConfig.TimeZone,
151+
NoCloudInit: !useCloudInit(instConfig),
146152
Param: instConfig.Param,
147153
}
148154

@@ -433,7 +439,7 @@ func GenerateISO9660(ctx context.Context, instDir, name string, instConfig *lima
433439
})
434440
}
435441

436-
if args.VMType == limayaml.WSL2 {
442+
if !useCloudInit(instConfig) {
437443
layout = append(layout, iso9660util.Entry{
438444
Path: "ssh_authorized_keys",
439445
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
@@ -105,6 +105,7 @@ type TemplateArgs struct {
105105
VirtioPort string
106106
Plain bool
107107
TimeZone string
108+
NoCloudInit bool
108109
}
109110

110111
func ValidateTemplateArgs(args *TemplateArgs) error {

0 commit comments

Comments
 (0)