Skip to content
Draft
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
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 Down
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 @@ -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}}
8 changes: 7 additions & 1 deletion pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Should be moved to the DriverFeatures struct in the driver infra)

}

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
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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")),
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type TemplateArgs struct {
VirtioPort string
Plain bool
TimeZone string
NoCloudInit bool
}

func ValidateTemplateArgs(args *TemplateArgs) error {
Expand Down
Loading