Skip to content

Commit

Permalink
Read kernel cmdline after env-vars
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Lönnegren <[email protected]>
  • Loading branch information
frelon committed Dec 14, 2023
1 parent 466d862 commit 3d53872
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ func ReadMountSpec(r *v1.RunConfig, flags *pflag.FlagSet) (*v1.MountSpec, error)
return mount, err
}

if err := applyKernelCmdline(r, mount); err != nil {
r.Logger.Errorf("Error reading kernel cmdline: %s", err.Error())
if err := applyMountEnvVars(r, mount); err != nil {
r.Logger.Errorf("Error reading mount env-vars: %s", err.Error())
return mount, err
}

if err := applyMountEnvVars(r, mount); err != nil {
r.Logger.Errorf("Error reading mount env-vars: %s", err.Error())
if err := applyKernelCmdline(r, mount); err != nil {
r.Logger.Errorf("Error reading kernel cmdline: %s", err.Error())
return mount, err
}

Expand Down
22 changes: 21 additions & 1 deletion cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ var _ = Describe("Config", Label("config"), func() {
fs, cleanup, err = vfst.NewTestFS(map[string]interface{}{})
Expect(err).Should(BeNil())

err = fs.Mkdir("/proc", constants.DirPerm)
Expect(err).Should(BeNil())
err = fs.WriteFile("/proc/cmdline", []byte("root=LABEL=COS_STATE elemental.image=active"), 0444)
Expect(err).Should(BeNil())

cfg, err = ReadConfigRun("fixtures/config/", nil, mounter)
Expect(err).Should(BeNil())

Expand Down Expand Up @@ -449,6 +454,21 @@ var _ = Describe("Config", Label("config"), func() {
Expect(spec.RecoveryUpgrade).To(BeTrue())
})
})

Describe("Read MountSpec", Label("mount"), func() {
It("inits a mount spec according to given configs", func() {
err := os.Setenv("ELEMENTAL_MOUNT_SYSROOT", "/newroot")
spec, err := ReadMountSpec(cfg, nil)
Expect(err).ShouldNot(HaveOccurred())
Expect(spec.Mode).To(Equal("active"))
Expect(spec.Sysroot).To(Equal("/newroot"))
})
It("picks kernel cmdline first then env-vars", func() {
err := os.Setenv("ELEMENTAL_MOUNT_IMAGE", "passive")
spec, err := ReadMountSpec(cfg, nil)
Expect(err).ShouldNot(HaveOccurred())
// Set by kernel cmdline
Expect(spec.Mode).To(Equal("active"))
})
})
})
})

0 comments on commit 3d53872

Please sign in to comment.