mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-10-21 03:27:33 +00:00
fix boot entry selecting with multiple extra cmdlines (#984)
This commit is contained in:
@@ -501,7 +501,7 @@ func ReadPersistentVariables(grubEnvFile string, c *agentConfig.Config) (map[str
|
||||
if err != nil {
|
||||
return vars, err
|
||||
}
|
||||
for _, a := range strings.Split(string(f), "\n") {
|
||||
for a := range strings.SplitSeq(string(f), "\n") {
|
||||
// comment or fillup, so skip
|
||||
if strings.HasPrefix(a, "#") {
|
||||
continue
|
||||
@@ -510,8 +510,8 @@ func ReadPersistentVariables(grubEnvFile string, c *agentConfig.Config) (map[str
|
||||
continue
|
||||
}
|
||||
splitted := strings.Split(a, "=")
|
||||
if len(splitted) == 2 {
|
||||
vars[splitted[0]] = splitted[1]
|
||||
if len(splitted) >= 2 {
|
||||
vars[splitted[0]] = strings.Join(splitted[1:], "=")
|
||||
} else {
|
||||
return vars, fmt.Errorf("invalid format for %s", a)
|
||||
}
|
||||
|
@@ -866,6 +866,22 @@ var _ = Describe("Utils", Label("utils"), func() {
|
||||
Expect(readVars["key2"]).To(Equal("value2"))
|
||||
Expect(readVars["key3"]).To(Equal("value4"))
|
||||
})
|
||||
It("Should work with multiple extra cmdline", func() {
|
||||
temp, err := os.CreateTemp("", "grub-*")
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
defer os.Remove(temp.Name())
|
||||
data := `# GRUB Environment Block
|
||||
extra_cmdline=fips=1 selinux=0
|
||||
########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################`
|
||||
Expect(fs.WriteFile(temp.Name(), []byte(data), constants.FilePerm)).To(BeNil())
|
||||
Expect(utils.SetPersistentVariables(
|
||||
temp.Name(), map[string]string{"next_entry": "statereset"}, config,
|
||||
)).To(BeNil())
|
||||
readVars, err := utils.ReadPersistentVariables(temp.Name(), config)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(readVars["next_entry"]).To(Equal("statereset"))
|
||||
Expect(readVars["extra_cmdline"]).To(Equal("fips=1 selinux=0"))
|
||||
})
|
||||
})
|
||||
})
|
||||
Describe("CreateSquashFS", Label("CreateSquashFS"), func() {
|
||||
|
Reference in New Issue
Block a user