Skip to content

Commit

Permalink
set default values depending on postgres version (#406)
Browse files Browse the repository at this point in the history
* set default values depending on postgres version

* Remove empty block to make linter happy

* Reduce default values
  • Loading branch information
eberlep authored Oct 18, 2023
1 parent 52e24d2 commit 8ac877b
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions api/v1/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const (
defaultPostgresParamValueSSLMinProtocolVersion = "TLSv1.2"
defaultPostgresParamValueSSLPreferServerCiphers = "on"
defaultPostgresParamValueSSLCiphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
defaultPostgresParamValueWalKeepSegements = "64"
defaultPostgresParamValueWalKeepSize = "1GB"
)

var (
Expand Down Expand Up @@ -541,7 +543,7 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
enableAuditLogs(z.Spec.PostgresqlParam.Parameters)
}
// set some default postgres parameters
setDefaultPostgresParams(z.Spec.PostgresqlParam.Parameters)
setDefaultPostgresParams(z.Spec.PostgresqlParam.Parameters, p.Spec.Version)
// now set the given generic parameters (and potentially allow overwriting of default postgres params or audit log params)
setPostgresParams(z.Spec.PostgresqlParam.Parameters, p.Spec.PostgresParams, pgParamBlockList)
// finally, overwrite the (special to us) shared buffer parameter
Expand Down Expand Up @@ -795,13 +797,31 @@ func enableAuditLogs(parameters map[string]string) {
}

// setDefaultPostgresParams configures default keepalive values
func setDefaultPostgresParams(parameters map[string]string) {
func setDefaultPostgresParams(parameters map[string]string, version string) {
// set default parameters
parameters["tcp_keepalives_idle"] = defaultPostgresParamValueTCPKeepAlivesIdle
parameters["tcp_keepalives_interval"] = defaultPostgresParamValueTCPKeepAlivesInterval
parameters["log_file_mode"] = defaultPostgresParamValueLogFileMode
parameters["ssl_min_protocol_version"] = defaultPostgresParamValueSSLMinProtocolVersion

parameters["ssl_prefer_server_ciphers"] = defaultPostgresParamValueSSLPreferServerCiphers
parameters["ssl_ciphers"] = defaultPostgresParamValueSSLCiphers

// set version specific parameters
v, err := strconv.Atoi(version)
if err != nil {
return
}
// Postgres 12 and up
if v >= 12 {
parameters["ssl_min_protocol_version"] = defaultPostgresParamValueSSLMinProtocolVersion
}
// Postgres 13 and up
if v >= 13 {
parameters["wal_keep_size"] = defaultPostgresParamValueWalKeepSize
} else {
parameters["wal_keep_segments"] = defaultPostgresParamValueWalKeepSegements
}

}

// setPostgresParams add the provided params to the parameter map (but ignore params that are blocked)
Expand Down

0 comments on commit 8ac877b

Please sign in to comment.