Skip to content

Commit 36de594

Browse files
authored
Merge pull request #3861 from afbjorklund/lima-init
Remove VMType check from the lima-init boot script
2 parents a95d097 + 78f6afc commit 36de594

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ LIMA_CIDATA_PLAIN=1
6565
{{- else}}
6666
LIMA_CIDATA_PLAIN=
6767
{{- end}}
68+
{{- if .NoCloudInit}}
69+
LIMA_CIDATA_NO_CLOUD_INIT=1
70+
{{- else}}
71+
LIMA_CIDATA_NO_CLOUD_INIT=
72+
{{- end}}

pkg/cidata/cidata.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func setupEnv(instConfigEnv map[string]string, propagateProxyEnv bool, slirpGate
118118
return env, nil
119119
}
120120

121-
func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string) (*TemplateArgs, error) {
121+
func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort, vsockPort int, virtioPort string, noCloudInit bool) (*TemplateArgs, error) {
122122
if err := limayaml.Validate(instConfig, false); err != nil {
123123
return nil, err
124124
}
@@ -138,12 +138,13 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
138138
Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive},
139139
SlirpNICName: networks.SlirpNICName,
140140

141-
VMType: *instConfig.VMType,
142-
VSockPort: vsockPort,
143-
VirtioPort: virtioPort,
144-
Plain: *instConfig.Plain,
145-
TimeZone: *instConfig.TimeZone,
146-
Param: instConfig.Param,
141+
VMType: *instConfig.VMType,
142+
VSockPort: vsockPort,
143+
VirtioPort: virtioPort,
144+
Plain: *instConfig.Plain,
145+
TimeZone: *instConfig.TimeZone,
146+
NoCloudInit: noCloudInit,
147+
Param: instConfig.Param,
147148
}
148149

149150
if instConfig.VMOpts.VZ.Rosetta.Enabled != nil {
@@ -350,7 +351,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
350351
}
351352

352353
func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML) error {
353-
args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "")
354+
args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "", false)
354355
if err != nil {
355356
return err
356357
}
@@ -372,8 +373,8 @@ func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *
372373
return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444)
373374
}
374375

375-
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 {
376-
args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort)
376+
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 {
377+
args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort, noCloudInit)
377378
if err != nil {
378379
return err
379380
}
@@ -466,7 +467,7 @@ func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name strin
466467
})
467468
}
468469

469-
if args.VMType == limatype.WSL2 {
470+
if noCloudInit {
470471
layout = append(layout, iso9660util.Entry{
471472
Path: "ssh_authorized_keys",
472473
Reader: strings.NewReader(strings.Join(args.SSHPubKeys, "\n")),

pkg/cidata/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type TemplateArgs struct {
114114
VirtioPort string
115115
Plain bool
116116
TimeZone string
117+
NoCloudInit bool
117118
}
118119

119120
func ValidateTemplateArgs(args *TemplateArgs) error {

pkg/driver/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ type DriverFeatures struct {
106106
CanRunGUI bool `json:"canRunGui,omitempty"`
107107
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
108108
SkipSocketForwarding bool `json:"skipSocketForwarding"`
109+
NoCloudInit bool `json:"noCloudInit"`
109110
}

pkg/driver/wsl2/boot/02-wsl2-setup.sh renamed to pkg/driver/wsl2/boot/02-no-cloud-init-setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
# This script replaces the cloud-init functionality of creating a user and setting its SSH keys
7-
# when using a WSL2 VM.
8-
[ "$LIMA_CIDATA_VMTYPE" = "wsl2" ] || exit 0
7+
# when cloud-init is not available
8+
[ "$LIMA_CIDATA_NO_CLOUD_INIT" = "1" ] || exit 0
99

1010
# create user
1111
# shellcheck disable=SC2153
@@ -22,4 +22,4 @@ chmod 600 "${LIMA_CIDATA_HOME}"/.ssh/authorized_keys
2222
echo "${LIMA_CIDATA_USER} ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers.d/99_lima_sudoers
2323

2424
# symlink CIDATA to the hardcoded path for requirement checks (TODO: make this not hardcoded)
25-
ln -sfFn "${LIMA_CIDATA_MNT}" /mnt/lima-cidata
25+
[ "$LIMA_CIDATA_MNT" = "/mnt/lima-cidata" ] || ln -sfFn "${LIMA_CIDATA_MNT}" /mnt/lima-cidata

pkg/driver/wsl2/wsl_driver_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func (l *LimaWslDriver) Info() driver.Info {
310310
info.Features = driver.DriverFeatures{
311311
DynamicSSHAddress: true,
312312
SkipSocketForwarding: true,
313+
NoCloudInit: true,
313314
CanRunGUI: l.canRunGUI(),
314315
}
315316
return info

pkg/hostagent/hostagent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ func New(ctx context.Context, instName string, stdout io.Writer, signalCh chan o
162162

163163
vSockPort := limaDriver.Info().VsockPort
164164
virtioPort := limaDriver.Info().VirtioPort
165+
noCloudInit := limaDriver.Info().Features.NoCloudInit
165166

166167
if err := cidata.GenerateCloudConfig(ctx, inst.Dir, instName, inst.Config); err != nil {
167168
return nil, err
168169
}
169-
if err := cidata.GenerateISO9660(ctx, limaDriver, inst.Dir, instName, inst.Config, udpDNSLocalPort, tcpDNSLocalPort, o.guestAgentBinary, o.nerdctlArchive, vSockPort, virtioPort); err != nil {
170+
if err := cidata.GenerateISO9660(ctx, limaDriver, inst.Dir, instName, inst.Config, udpDNSLocalPort, tcpDNSLocalPort, o.guestAgentBinary, o.nerdctlArchive, vSockPort, virtioPort, noCloudInit); err != nil {
170171
return nil, err
171172
}
172173

0 commit comments

Comments
 (0)