Skip to content

Commit 076273e

Browse files
mnenciaarmru
andauthored
fix: ignore internal configs in config hash calculation (#8868)
Closes #8371 Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Armando Ruocco <[email protected]>
1 parent 93f02f4 commit 076273e

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎pkg/postgres/configuration.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,19 +860,26 @@ func CreatePostgresqlConfFile(configuration *PgConfiguration) (string, string) {
860860
// that we sort the configuration by parameter name as order
861861
// is really irrelevant for our purposes
862862
parameters := configuration.GetSortedList()
863-
postgresConf := ""
863+
var postgresConf strings.Builder
864+
var cnpgConf strings.Builder
864865
for _, parameter := range parameters {
865-
postgresConf += fmt.Sprintf(
866+
line := fmt.Sprintf(
866867
"%v = %v\n",
867868
parameter,
868869
escapePostgresConfValue(configuration.configs[parameter]))
870+
if strings.HasPrefix(parameter, "cnpg.") {
871+
cnpgConf.WriteString(line)
872+
} else {
873+
postgresConf.WriteString(line)
874+
}
869875
}
870876

871-
sha256sum := fmt.Sprintf("%x", sha256.Sum256([]byte(postgresConf)))
872-
postgresConf += fmt.Sprintf("%v = %v", CNPGConfigSha256,
873-
escapePostgresConfValue(sha256sum))
877+
sha256sum := fmt.Sprintf("%x", sha256.Sum256([]byte(postgresConf.String())))
878+
postgresConf.WriteString(cnpgConf.String())
879+
postgresConf.WriteString(fmt.Sprintf("%v = %v\n", CNPGConfigSha256,
880+
escapePostgresConfValue(sha256sum)))
874881

875-
return postgresConf, sha256sum
882+
return postgresConf.String(), sha256sum
876883
}
877884

878885
// escapePostgresConfValue escapes a value to make its representation

‎pkg/postgres/configuration_test.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ var _ = Describe("PostgreSQL configuration creation", func() {
7171
Expect(len(strings.Split(confFile, "\n"))).To(BeNumerically(">", 2))
7272
})
7373

74+
It("ignores internal configs in config hash", func() {
75+
info := ConfigurationInfo{
76+
Settings: CnpgConfigurationSettings,
77+
MajorVersion: 17,
78+
UserSettings: settings,
79+
IncludingMandatory: true,
80+
}
81+
conf := CreatePostgresqlConfiguration(info)
82+
confFile, sha256 := CreatePostgresqlConfFile(conf)
83+
Expect(sha256).NotTo(BeEmpty())
84+
Expect(confFile).To(Not(BeEmpty()))
85+
86+
conf.OverwriteConfig("cnpg.some_internal_setting", "some_value")
87+
newConfFile, newSha256 := CreatePostgresqlConfFile(conf)
88+
Expect(newSha256).NotTo(BeEmpty())
89+
Expect(newConfFile).To(Not(BeEmpty()))
90+
Expect(newSha256).To(Equal(sha256))
91+
Expect(newConfFile).To(Not(BeEquivalentTo(confFile)))
92+
})
93+
7494
It("is sorted by parameter name", func() {
7595
settings := map[string]string{
7696
"shared_buffers": "128KB",

0 commit comments

Comments
 (0)