@@ -16,6 +16,7 @@ import (
1616 "github.com/containers/common/pkg/strongunits"
1717 gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
1818 "github.com/containers/podman/v5/pkg/machine"
19+ "github.com/containers/podman/v5/pkg/machine/cloudinit"
1920 "github.com/containers/podman/v5/pkg/machine/define"
2021 "github.com/containers/podman/v5/pkg/machine/ignition"
2122 "github.com/containers/podman/v5/pkg/machine/sockets"
@@ -141,10 +142,6 @@ func GenerateSystemDFilesForVirtiofsMounts(mounts []machine.VirtIoFs) ([]ignitio
141142
142143// StartGenericAppleVM is wrapped by apple provider methods and starts the vm
143144func StartGenericAppleVM (mc * vmconfigs.MachineConfig , cmdBinary string , bootloader vfConfig.Bootloader , endpoint string ) (func () error , func () error , error ) {
144- var (
145- ignitionSocket * define.VMFile
146- )
147-
148145 // Add networking
149146 netDevice , err := vfConfig .VirtioNetNew (applehvMACAddress )
150147 if err != nil {
@@ -209,11 +206,6 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
209206 return nil , nil , err
210207 }
211208
212- machineDataDir , err := mc .DataDir ()
213- if err != nil {
214- return nil , nil , err
215- }
216-
217209 cmd .Args = append (cmd .Args , endpointArgs ... )
218210
219211 firstBoot , err := mc .IsFirstBoot ()
@@ -231,31 +223,18 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
231223 }
232224
233225 if firstBoot {
234- // If this is the first boot of the vm, we need to add the vsock
235- // device to vfkit so we can inject the ignition file
236- socketName := fmt .Sprintf ("%s-%s" , mc .Name , ignitionSocketName )
237- ignitionSocket , err = machineDataDir .AppendToNewVMFile (socketName , & socketName )
238- if err != nil {
239- return nil , nil , err
240- }
241- if err := ignitionSocket .Delete (); err != nil {
242- logrus .Errorf ("unable to delete ignition socket: %q" , err )
226+ var firstBootCli []string
227+ if mc .CloudInit {
228+ firstBootCli , err = getFirstBootAppleVMCloudInit (mc )
229+ } else {
230+ firstBootCli , err = getFirstBootAppleVMIgnition (mc )
243231 }
244232
245- ignitionVsockDeviceCLI , err := GetIgnitionVsockDeviceAsCLI (ignitionSocket .GetPath ())
246233 if err != nil {
247234 return nil , nil , err
248235 }
249- cmd .Args = append (cmd .Args , ignitionVsockDeviceCLI ... )
250-
251236 logrus .Debug ("first boot detected" )
252- logrus .Debugf ("serving ignition file over %s" , ignitionSocket .GetPath ())
253- go func () {
254- if err := ServeIgnitionOverSock (ignitionSocket , mc ); err != nil {
255- logrus .Error (err )
256- }
257- logrus .Debug ("ignition vsock server exited" )
258- }()
237+ cmd .Args = append (cmd .Args , firstBootCli ... )
259238 }
260239
261240 logrus .Debugf ("listening for ready on: %s" , readySocket .GetPath ())
@@ -351,6 +330,68 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload
351330 return cmd .Process .Release , returnFunc , nil
352331}
353332
333+ func getFirstBootAppleVMIgnition (mc * vmconfigs.MachineConfig ) ([]string , error ) {
334+ machineDataDir , err := mc .DataDir ()
335+ if err != nil {
336+ return nil , err
337+ }
338+
339+ // If this is the first boot of the vm, we need to add the vsock
340+ // device to vfkit so we can inject the ignition file
341+ socketName := fmt .Sprintf ("%s-%s" , mc .Name , ignitionSocketName )
342+ ignitionSocket , err := machineDataDir .AppendToNewVMFile (socketName , & socketName )
343+ if err != nil {
344+ return nil , err
345+ }
346+ if err := ignitionSocket .Delete (); err != nil {
347+ logrus .Errorf ("unable to delete ignition socket: %q" , err )
348+ }
349+
350+ ignitionVsockDeviceCLI , err := GetIgnitionVsockDeviceAsCLI (ignitionSocket .GetPath ())
351+ if err != nil {
352+ return nil , err
353+ }
354+
355+ logrus .Debugf ("serving ignition file over %s" , ignitionSocket .GetPath ())
356+ go func () {
357+ if err := ServeIgnitionOverSock (ignitionSocket , mc ); err != nil {
358+ logrus .Error (err )
359+ }
360+ logrus .Debug ("ignition vsock server exited" )
361+ }()
362+
363+ return ignitionVsockDeviceCLI , nil
364+ }
365+
366+ func getFirstBootAppleVMCloudInit (mc * vmconfigs.MachineConfig ) ([]string , error ) {
367+ sshKey , err := machine .GetSSHKeys (mc .SSH .IdentityPath )
368+ if err != nil {
369+ return nil , err
370+ }
371+
372+ tempDir , err := os .MkdirTemp ("" , "cloud-init-macadam-" )
373+ if err != nil {
374+ return nil , err
375+ }
376+
377+ // we generate the user-data file
378+ userDataFile , err := cloudinit .GenerateUserData (tempDir , cloudinit.UserData {
379+ Users : []cloudinit.User {
380+ cloudinit.User {
381+ Name : mc .SSH .RemoteUsername ,
382+ Sudo : "ALL=(ALL) NOPASSWD:ALL" ,
383+ Shell : "/bin/bash" ,
384+ Groups : "users" ,
385+ SSHKeys : []string {
386+ sshKey ,
387+ },
388+ },
389+ },
390+ })
391+
392+ return []string {"--cloud-init" , userDataFile }, nil
393+ }
394+
354395// CheckProcessRunning checks non blocking if the pid exited
355396// returns nil if process is running otherwise an error if not
356397func CheckProcessRunning (processName string , pid int ) error {
0 commit comments