Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/lima.env
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
23 changes: 12 additions & 11 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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")),
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type TemplateArgs struct {
VirtioPort string
Plain bool
TimeZone string
NoCloudInit bool
}

func ValidateTemplateArgs(args *TemplateArgs) error {
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ type DriverFeatures struct {
CanRunGUI bool `json:"canRunGui,omitempty"`
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
SkipSocketForwarding bool `json:"skipSocketForwarding"`
NoCloudInit bool `json:"noCloudInit"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions pkg/driver/wsl2/wsl_driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down