CreatePostgresqlConfFile creates the contents of the postgresql.conf file
(configuration *PgConfiguration)
| 869 | |
| 870 | // CreatePostgresqlConfFile creates the contents of the postgresql.conf file |
| 871 | func CreatePostgresqlConfFile(configuration *PgConfiguration) (string, string) { |
| 872 | // Split the parameters into the regular PostgreSQL section (whose hash |
| 873 | // defines the identity of the configuration) and the cnpg.* section (which |
| 874 | // carries operator-internal state and must not contribute to the hash). |
| 875 | pgOptions := map[string]string{} |
| 876 | cnpgOptions := map[string]string{} |
| 877 | for name, value := range configuration.configs { |
| 878 | if strings.HasPrefix(name, "cnpg.") { |
| 879 | cnpgOptions[name] = value |
| 880 | } else { |
| 881 | pgOptions[name] = value |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | pgPart := configfile.RenderPostgresConfiguration(pgOptions) |
| 886 | sha256sum := fmt.Sprintf("%x", sha256.Sum256([]byte(pgPart))) |
| 887 | |
| 888 | // Emit the cnpg.* keys (sorted), then always emit the sha256 line LAST. |
| 889 | // The sha256-last layout is legacy behaviour; preserving it prevents a |
| 890 | // byte-level diff in postgresql.conf (and an avoidable pg_reload_conf()) |
| 891 | // on operator upgrade for clusters that already have other cnpg.* keys |
| 892 | // such as cnpg.synchronous_standby_names_metadata. |
| 893 | cnpgPart := configfile.RenderPostgresConfiguration(cnpgOptions) |
| 894 | sha256Line := configfile.RenderPostgresConfiguration(map[string]string{ |
| 895 | CNPGConfigSha256: sha256sum, |
| 896 | }) |
| 897 | |
| 898 | return pgPart + cnpgPart + sha256Line, sha256sum |
| 899 | } |
| 900 | |
| 901 | // AdditionalExtensionConfiguration is the configuration for an Extension added via ImageVolume |
| 902 | type AdditionalExtensionConfiguration struct { |