diff --git a/pkg/common/file.go b/pkg/common/file.go index e57e58d0da..8637fc4850 100644 --- a/pkg/common/file.go +++ b/pkg/common/file.go @@ -182,9 +182,9 @@ func setConfigOption(configName, configValue string, yamlData *yaml.Node) { for indx := 0; indx < contentLen-1; { name := yamlData.Content[0].Content[indx].Value if name == configName { + // Set the value, even if we have the option defined multiple times. yamlData.Content[0].Content[indx+1].Value = configValue foundOption = true - break } indx += 2 } diff --git a/test/e2e/config_test.go b/test/e2e/config_test.go index 822b9c9fc4..8c9043fa8e 100644 --- a/test/e2e/config_test.go +++ b/test/e2e/config_test.go @@ -87,4 +87,42 @@ pull-image-on-create: false disable-pull-on-run: false `)) }) + + It("should succeed to get the right value if duplicate entries are defined", func() { + _, err := configFile.WriteString(` +timeout: 20 +timeout: 5 +timeout: 10 +`) + Expect(err).NotTo(HaveOccurred()) + + t.CrictlExpectSuccess("--config "+configFile.Name()+" config --get timeout", "10") + }) + + It("should succeed to set duplicate entries", func() { + _, err := configFile.WriteString(` +timeout: 20 +timeout: 5 +timeout: 10 +`) + Expect(err).NotTo(HaveOccurred()) + + t.CrictlExpectSuccess("--config "+configFile.Name()+" config --set timeout=30", "") + + cfgContent, err := os.ReadFile(configFile.Name()) + Expect(err).NotTo(HaveOccurred()) + + Expect(string(cfgContent)).To(Equal( + `timeout: 30 +timeout: 30 +timeout: 30 +runtime-endpoint: "" +image-endpoint: "" +debug: false +pull-image-on-create: false +disable-pull-on-run: false +`)) + + t.CrictlExpectSuccess("--config "+configFile.Name()+" config --get timeout", "30") + }) })