Skip to content

Commit 06b4afa

Browse files
committed
Add feature for CloudInit instead of VMType name
Instead of hardcoding which drivers do not use cloud-init, make it into a driver feature. Currently, that is only WSL2. The container drivers do mount a cidata.iso, instead they mount a cidata dir. Then they include a boot script for it. Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
1 parent f83aa9b commit 06b4afa

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

pkg/cidata/cidata.go

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

121-
func useCloudInit(instConfig *limayaml.LimaYAML) bool {
122-
// all drivers but WSL2 use cloud-init
123-
return *instConfig.VMType != limayaml.WSL2
124-
}
125-
126-
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) {
127122
if err := limayaml.Validate(instConfig, false); err != nil {
128123
return nil, err
129124
}
@@ -148,7 +143,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
148143
VirtioPort: virtioPort,
149144
Plain: *instConfig.Plain,
150145
TimeZone: *instConfig.TimeZone,
151-
NoCloudInit: !useCloudInit(instConfig),
146+
NoCloudInit: noCloudInit,
152147
Param: instConfig.Param,
153148
}
154149

@@ -356,7 +351,7 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
356351
}
357352

358353
func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML) error {
359-
args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "")
354+
args, err := templateArgs(ctx, false, instDir, name, instConfig, 0, 0, 0, "", false)
360355
if err != nil {
361356
return err
362357
}
@@ -378,8 +373,8 @@ func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *
378373
return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444)
379374
}
380375

381-
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 {
382-
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)
383378
if err != nil {
384379
return err
385380
}
@@ -472,7 +467,7 @@ func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name strin
472467
})
473468
}
474469

475-
if !useCloudInit(instConfig) {
470+
if noCloudInit {
476471
layout = append(layout, iso9660util.Entry{
477472
Path: "ssh_authorized_keys",
478473
Reader: strings.NewReader(strings.Join(args.SSHPubKeys, "\n")),

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+
NoCloudConfig bool `json:"noCloudConfig"`
109110
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
NoCloudConfig: 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+
noCloudConfig := limaDriver.Info().Features.NoCloudConfig
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, noCloudConfig); err != nil {
170171
return nil, err
171172
}
172173

0 commit comments

Comments
 (0)