Fix init teardown on bad ignition path

Fixes a bug where if a machine failed during init due to a bad ignition path, it would not be properly torn down.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
This commit is contained in:
Jake Correnti
2024-01-04 20:35:45 -05:00
parent b01a330d37
commit 3bfdd79150
4 changed files with 19 additions and 15 deletions

View File

@ -259,7 +259,8 @@ func (m *MacMachine) Init(opts machine.InitOptions) (bool, error) {
})
if len(opts.IgnitionPath) > 0 {
return false, builder.BuildWithIgnitionFile(opts.IgnitionPath)
err = builder.BuildWithIgnitionFile(opts.IgnitionPath)
return false, err
}
if err := builder.GenerateIgnitionConfig(); err != nil {

View File

@ -313,20 +313,21 @@ var _ = Describe("podman machine init", func() {
Expect(err).ToNot(HaveOccurred())
Expect(ec).To(Equal(125))
// Clashing keys - init fails
i = new(initMachine)
session, err = mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(125))
// ensure files created by init are cleaned up on init failure
_, err = os.Stat(img)
Expect(err).To(HaveOccurred())
_, err = os.Stat(cfgpth)
Expect(err).To(HaveOccurred())
// WSL does not use ignition
if testProvider.VMType() != define.WSLVirt {
// Bad ignition path - init fails
i = new(initMachine)
i.ignitionPath = "/bad/path"
session, err = mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(125))
// ensure files created by init are cleaned up on init failure
_, err = os.Stat(img)
Expect(err).To(HaveOccurred())
_, err = os.Stat(cfgpth)
Expect(err).To(HaveOccurred())
_, err = os.Stat(ign)
Expect(err).To(HaveOccurred())
}

View File

@ -232,7 +232,8 @@ func (m *HyperVMachine) Init(opts machine.InitOptions) (bool, error) {
// If the user provides an ignition file, we need to
// copy it into the conf dir
if len(opts.IgnitionPath) > 0 {
return false, builder.BuildWithIgnitionFile(opts.IgnitionPath)
err = builder.BuildWithIgnitionFile(opts.IgnitionPath)
return false, err
}
callbackFuncs.Add(m.IgnitionFile.Delete)

View File

@ -205,7 +205,8 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
// If the user provides an ignition file, we need to
// copy it into the conf dir
if len(opts.IgnitionPath) > 0 {
return false, builder.BuildWithIgnitionFile(opts.IgnitionPath)
err = builder.BuildWithIgnitionFile(opts.IgnitionPath)
return false, err
}
if err := builder.GenerateIgnitionConfig(); err != nil {