diff --git a/pkg/cidata/cidata.TEMPLATE.d/lima.env b/pkg/cidata/cidata.TEMPLATE.d/lima.env index e08129b5a22..8cd9453ccdc 100644 --- a/pkg/cidata/cidata.TEMPLATE.d/lima.env +++ b/pkg/cidata/cidata.TEMPLATE.d/lima.env @@ -65,3 +65,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 4a38c0c2fbf..ad024acba14 100644 --- a/pkg/cidata/cidata.go +++ b/pkg/cidata/cidata.go @@ -118,7 +118,7 @@ func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGate return env, nil } -func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) { +func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string, noCloudInit bool) (*TemplateArgs, error) { if err := limayaml.Validate(instConfig, false); err != nil { return nil, err } @@ -138,12 +138,13 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive}, SlirpNICName: networks.SlirpNICName, - VMType: *instConfig.VMType, - VSockPort: vsockPort, - VirtioPort: virtioPort, - Plain: *instConfig.Plain, - TimeZone: *instConfig.TimeZone, - Param: instConfig.Param, + VMType: *instConfig.VMType, + VSockPort: vsockPort, + VirtioPort: virtioPort, + Plain: *instConfig.Plain, + TimeZone: *instConfig.TimeZone, + NoCloudInit: noCloudInit, + Param: instConfig.Param, } if instConfig.VMOpts.VZ.Rosetta.Enabled != nil { @@ -350,7 +351,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i } func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML) error { - args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "") + args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "", false) if err != nil { return err } @@ -372,8 +373,8 @@ func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig * return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444) } -func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string) error { - args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort) +func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string, noCloudInit bool) error { + args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort, noCloudInit) if err != nil { return err } @@ -466,7 +467,7 @@ func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name strin }) } - if args.VMType == limatype.WSL2 { + if noCloudInit { 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 3d886e7a5e6..84dfafce86d 100644 --- a/pkg/cidata/template.go +++ b/pkg/cidata/template.go @@ -114,6 +114,7 @@ type TemplateArgs struct { VirtioPort string Plain bool TimeZone string + NoCloudInit bool } func ValidateTemplateArgs(args *TemplateArgs) error { diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 94c192f0cd4..fc3a1afd653 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -106,4 +106,5 @@ type DriverFeatures struct { CanRunGUI bool `json:"canRunGui,omitempty"` DynamicSSHAddress bool `json:"dynamicSSHAddress"` SkipSocketForwarding bool `json:"skipSocketForwarding"` + NoCloudInit bool `json:"noCloudInit"` } diff --git a/pkg/driver/wsl2/boot/02-wsl2-setup.sh b/pkg/driver/wsl2/boot/02-no-cloud-init-setup.sh similarity index 85% rename from pkg/driver/wsl2/boot/02-wsl2-setup.sh rename to pkg/driver/wsl2/boot/02-no-cloud-init-setup.sh index cb5639657d3..ebfe351cd3e 100755 --- a/pkg/driver/wsl2/boot/02-wsl2-setup.sh +++ b/pkg/driver/wsl2/boot/02-no-cloud-init-setup.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 @@ -22,4 +22,4 @@ chmod 600 "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys echo "${LIMA_CIDATA_USER} ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers.d/99_lima_sudoers # symlink CIDATA to the hardcoded path for requirement checks (TODO: make this not hardcoded) -ln -sfFn "${LIMA_CIDATA_MNT}" /mnt/lima-cidata +[ "$LIMA_CIDATA_MNT" = "/mnt/lima-cidata" ] || ln -sfFn "${LIMA_CIDATA_MNT}" /mnt/lima-cidata diff --git a/pkg/driver/wsl2/wsl_driver_windows.go b/pkg/driver/wsl2/wsl_driver_windows.go index 17886de8863..ae8252b1639 100644 --- a/pkg/driver/wsl2/wsl_driver_windows.go +++ b/pkg/driver/wsl2/wsl_driver_windows.go @@ -310,6 +310,7 @@ func (l *LimaWslDriver) Info() driver.Info { info.Features = driver.DriverFeatures{ DynamicSSHAddress: true, SkipSocketForwarding: true, + NoCloudInit: true, CanRunGUI: l.canRunGUI(), } return info diff --git a/pkg/hostagent/hostagent.go b/pkg/hostagent/hostagent.go index 3affdf6b0c1..41738e2d28e 100644 --- a/pkg/hostagent/hostagent.go +++ b/pkg/hostagent/hostagent.go @@ -162,11 +162,12 @@ func New(ctx context.Context, instName string, stdout io.Writer, signalCh chan o vSockPort := limaDriver.Info().VsockPort virtioPort := limaDriver.Info().VirtioPort + noCloudInit := limaDriver.Info().Features.NoCloudInit if err := cidata.GenerateCloudConfig(ctx, inst.Dir, instName, inst.Config); err != nil { return nil, err } - if err := cidata.GenerateISO9660(ctx, limaDriver, inst.Dir, instName, inst.Config, udpDNSLocalPort, tcpDNSLocalPort, o.guestAgentBinary, o.nerdctlArchive, vSockPort, virtioPort); err != nil { + if err := cidata.GenerateISO9660(ctx, limaDriver, inst.Dir, instName, inst.Config, udpDNSLocalPort, tcpDNSLocalPort, o.guestAgentBinary, o.nerdctlArchive, vSockPort, virtioPort, noCloudInit); err != nil { return nil, err }