MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / DynamicConfiguration

Function DynamicConfiguration

internal/patroni/config.go:211–287  ·  view source on GitHub ↗

DynamicConfiguration combines configuration with some PostgreSQL settings and returns a value that can be marshaled to JSON.

(
	spec *v1beta1.PostgresClusterSpec,
	pgHBAs *postgres.OrderedHBAs, parameters *postgres.ParameterSet,
)

Source from the content-addressed store, hash-verified

209// DynamicConfiguration combines configuration with some PostgreSQL settings
210// and returns a value that can be marshaled to JSON.
211func DynamicConfiguration(
212 spec *v1beta1.PostgresClusterSpec,
213 pgHBAs *postgres.OrderedHBAs, parameters *postgres.ParameterSet,
214) map[string]any {
215 // Copy the entire configuration before making any changes.
216 root := make(map[string]any)
217 if spec.Patroni != nil && spec.Patroni.DynamicConfiguration != nil {
218 root = spec.Patroni.DynamicConfiguration.DeepCopy()
219 }
220
221 // NOTE: These are always populated due to [v1beta1.PatroniSpec.Default]
222 root["ttl"] = *spec.Patroni.LeaderLeaseDurationSeconds
223 root["loop_wait"] = *spec.Patroni.SyncPeriodSeconds
224
225 postgresql := map[string]any{
226 // TODO(cbandy): explain this. requires an archive, perhaps.
227 "use_slots": false,
228 }
229
230 // Copy the "postgresql" section over the above defaults.
231 if section, ok := root["postgresql"].(map[string]any); ok {
232 maps.Copy(postgresql, section)
233 }
234 if m := parameters.AsMap(); m != nil {
235 postgresql["parameters"] = m
236 }
237 if pgHBAs != nil {
238 postgresql["pg_hba"] = pgHBAs.AsStrings()
239 }
240 root["postgresql"] = postgresql
241
242 // Enabling `pg_rewind` allows a former primary to automatically rejoin the
243 // cluster even if it has commits that were not sent to a replica. In other
244 // words, this favors availability over consistency. Without it, the former
245 // primary needs patronictl reinit to rejoin.
246 //
247 // Recent versions of `pg_rewind` can run with limited permissions granted
248 // by Patroni to the user defined in "postgresql.authentication.rewind".
249 // PostgreSQL v10 and earlier require superuser access over the network.
250 postgresql["use_pg_rewind"] = spec.PostgresVersion > 10
251
252 if spec.Standby != nil && spec.Standby.Enabled {
253 standby, _ := root["standby_cluster"].(map[string]any)
254 if standby == nil {
255 standby = make(map[string]any)
256 }
257
258 // Unset any previous value for restore_command - we will set it later if needed
259 delete(standby, "restore_command")
260
261 // Populate replica creation methods based on options provided in the standby spec:
262 methods := []string{}
263 if spec.Standby.Host != "" {
264 standby["host"] = spec.Standby.Host
265 if spec.Standby.Port != nil {
266 standby["port"] = *spec.Standby.Port
267 }
268

Callers 3

TestDynamicConfigurationFunction · 0.85
clusterYAMLFunction · 0.85

Calls 4

AsMapMethod · 0.80
AsStringsMethod · 0.80
ValueMethod · 0.80
DeepCopyMethod · 0.45

Tested by 1

TestDynamicConfigurationFunction · 0.68