diff --git a/pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh b/pkg/cidata/cidata.TEMPLATE.d/boot/02-no-cloud-init.sh similarity index 92% rename from pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh rename to pkg/cidata/cidata.TEMPLATE.d/boot/02-no-cloud-init.sh index cb5639657d3..0a4d86f42d1 100755 --- a/pkg/cidata/cidata.TEMPLATE.d/boot/02-wsl2-setup.sh +++ b/pkg/cidata/cidata.TEMPLATE.d/boot/02-no-cloud-init.sh @@ -4,8 +4,8 @@ # SPDX-License-Identifier: Apache-2.0 # This script replaces the cloud-init functionality of creating a user and setting its SSH keys -# when using a WSL2 VM. -[ "$LIMA_CIDATA_VMTYPE" = "wsl2" ] || exit 0 +# when cloud-init is not available +[ "$LIMA_CIDATA_NO_CLOUD_INIT" = "1" ] || exit 0 # create user # shellcheck disable=SC2153 diff --git a/pkg/cidata/cidata.TEMPLATE.d/lima.env b/pkg/cidata/cidata.TEMPLATE.d/lima.env index 89d2d34f108..d4ec3ef943b 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/lima.env +++ b/pkg/cidata/cidata.TEMPLATE.d/lima.env @@ -59,3 +59,8 @@ LIMA_CIDATA_PLAIN=1 {{- else}} LIMA_CIDATA_PLAIN= {{- end}} +{{- if .NoCloudInit}} +LIMA_CIDATA_NO_CLOUD_INIT=1 +{{- else}} +LIMA_CIDATA_NO_CLOUD_INIT= +{{- end}} diff --git a/pkg/cidata/cidata.go b/pkg/cidata/cidata.go index 0a8c57aa9c9..513a1e8b549 100644 --- a/pkg/cidata/cidata.go +++ b/pkg/cidata/cidata.go @@ -116,6 +116,11 @@ func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGate return env, nil } +func useCloudInit(instConfig *limayaml.LimaYAML) bool { + // all drivers but WSL2 use cloud-init + return *instConfig.VMType != limayaml.WSL2 +} + func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limayaml.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) { if err := limayaml.Validate(instConfig, false); err != nil { return nil, err @@ -143,6 +148,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i VirtioPort: virtioPort, Plain: *instConfig.Plain, TimeZone: *instConfig.TimeZone, + NoCloudInit: !useCloudInit(instConfig), Param: instConfig.Param, } @@ -433,7 +439,7 @@ func GenerateISO9660(ctx context.Context, instDir, name string, instConfig *lima }) } - if args.VMType == limayaml.WSL2 { + if !useCloudInit(instConfig) { layout = append(layout, iso9660util.Entry{ Path: "ssh_authorized_keys", Reader: strings.NewReader(strings.Join(args.SSHPubKeys, "\n")), diff --git a/pkg/cidata/template.go b/pkg/cidata/template.go index 33825b3ba18..8d84c55f085 100644 --- a/pkg/cidata/template.go +++ b/pkg/cidata/template.go @@ -105,6 +105,7 @@ type TemplateArgs struct { VirtioPort string Plain bool TimeZone string + NoCloudInit bool } func ValidateTemplateArgs(args *TemplateArgs) error {