From 94551efbc04761036c915392c518258bef29b8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 18 Aug 2025 22:28:20 +0200 Subject: [PATCH] Remove VMType check from the lima-init boot script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../boot/{02-wsl2-setup.sh => 02-no-cloud-init.sh} | 4 ++-- pkg/cidata/cidata.TEMPLATE.d/lima.env | 5 +++++ pkg/cidata/cidata.go | 8 +++++++- pkg/cidata/template.go | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) rename pkg/cidata/cidata.TEMPLATE.d/boot/{02-wsl2-setup.sh => 02-no-cloud-init.sh} (92%) 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 {