Skip to content

Commit 34a15ae

Browse files
Graceson Aufderheidegaufde
Graceson Aufderheide
authored andcommitted
fix podman machine init --ignition-path
Fix the issue where podman machine init does not create all the necessary machine files when ignition-path is used. Fixes: #23544 Signed-off-by: Graceson Aufderheide <[email protected]>
1 parent 290d94d commit 34a15ae

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

pkg/machine/e2e/config_init_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ func (i *initMachine) buildCmd(m *machineTestBuilder) []string {
9090
if strings.Contains(session.errorToString(), "VM does not exist") {
9191
return
9292
}
93+
94+
// FIXME:#24344 work-around for custom ignition removal
95+
if strings.Contains(session.errorToString(), "failed to remove machines files: unable to find connection named") {
96+
return
97+
}
9398
}
9499
Expect(session).To(Exit(0))
95100
})

pkg/machine/e2e/init_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,50 @@ var _ = Describe("podman machine init", func() {
224224
Expect(sshSession.outputToString()).To(ContainSubstring("example"))
225225
})
226226

227+
It("machine init with ignition path", func() {
228+
skipIfWSL("Ignition is not compatible with WSL machines since they are not based on Fedora CoreOS")
229+
230+
tmpDir, err := os.MkdirTemp("", "")
231+
defer func() { _ = utils.GuardedRemoveAll(tmpDir) }()
232+
Expect(err).ToNot(HaveOccurred())
233+
234+
tmpFile, err := os.CreateTemp(tmpDir, "test-ignition-*.ign")
235+
Expect(err).ToNot(HaveOccurred())
236+
237+
mockIgnitionContent := `{"ignition":{"version":"3.4.0"},"passwd":{"users":[{"name":"core"}]}}`
238+
239+
_, err = tmpFile.WriteString(mockIgnitionContent)
240+
Expect(err).ToNot(HaveOccurred())
241+
242+
err = tmpFile.Close()
243+
Expect(err).ToNot(HaveOccurred())
244+
245+
name := randomString()
246+
i := new(initMachine)
247+
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withIgnitionPath(tmpFile.Name())).run()
248+
Expect(err).ToNot(HaveOccurred())
249+
Expect(session).To(Exit(0))
250+
251+
configDir := filepath.Join(testDir, ".config", "containers", "podman", "machine", testProvider.VMType().String())
252+
253+
// test that all required machine files are created
254+
fileExtensions := []string{".lock", ".json", ".ign"}
255+
for _, ext := range fileExtensions {
256+
filename := filepath.Join(configDir, fmt.Sprintf("%s%s", name, ext))
257+
258+
_, err := os.Stat(filename)
259+
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("file %v does not exist", filename))
260+
}
261+
262+
// enforce that the raw ignition is copied over verbatim
263+
createdIgn := filepath.Join(configDir, fmt.Sprintf("%s%s", name, ".ign"))
264+
contentWanted, err := os.ReadFile(tmpFile.Name())
265+
Expect(err).ToNot(HaveOccurred())
266+
contentGot, err := os.ReadFile(createdIgn)
267+
Expect(err).ToNot(HaveOccurred())
268+
Expect(contentWanted).To(Equal(contentGot), "The ignition file provided and the ignition file created do not match")
269+
})
270+
227271
It("machine init rootless docker.sock check", func() {
228272
i := initMachine{}
229273
name := randomString()

pkg/machine/shim/host.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,15 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) error {
196196
// copy it into the conf dir
197197
if len(opts.IgnitionPath) > 0 {
198198
err = ignBuilder.BuildWithIgnitionFile(opts.IgnitionPath)
199-
return err
200-
}
201199

202-
err = ignBuilder.GenerateIgnitionConfig()
203-
if err != nil {
204-
return err
200+
if err != nil {
201+
return err
202+
}
203+
} else {
204+
err = ignBuilder.GenerateIgnitionConfig()
205+
if err != nil {
206+
return err
207+
}
205208
}
206209

207210
readyIgnOpts, err := mp.PrepareIgnition(mc, &ignBuilder)
@@ -245,9 +248,10 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) error {
245248
return err
246249
}
247250

248-
err = ignBuilder.Build()
249-
if err != nil {
250-
return err
251+
if len(opts.IgnitionPath) == 0 {
252+
if err := ignBuilder.Build(); err != nil {
253+
return err
254+
}
251255
}
252256

253257
return mc.Write()

0 commit comments

Comments
 (0)