Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9f9c439
Adds a New Condition for PVC Resize Errors
andrewlecuyer Feb 7, 2025
a942197
Initial configuration for an OpenTelemetry Collector
cbandy Dec 23, 2024
3ea8f17
Add an OTel Collector with Patroni metrics
dsessler7 Jan 6, 2025
c3a98fb
Add PgBouncer metrics
dsessler7 Jan 14, 2025
9fcef77
Parse Postgres and pgAudit logs using the OTel Collector
benjaminjb Jan 22, 2025
08ab9a4
Parse Patroni logs
dsessler7 Jan 22, 2025
2e59c1b
Parse PgBouncer logs using the OTel Collector
dsessler7 Jan 29, 2025
96e1ffb
Scrape pgAdmin logs using the OTel collector
tony-landreth Jan 29, 2025
ee9bf60
Add pgBackRest repohost log collector
benjaminjb Feb 1, 2025
836572d
Validate and strip/minify Collector SQL files
cbandy Feb 7, 2025
f2a80ac
Change pgbackrest init for running containers
benjaminjb Feb 7, 2025
0dcb1be
Bump controller-gen to v0.17.2
cbandy Feb 10, 2025
fbb4f32
Change PostgresIdentifier to a type alias
cbandy Jan 3, 2025
7089149
Add k8s attributes to patroni logs. Add CompactingProcessor to patron…
dsessler7 Feb 7, 2025
8e37a1f
Create initial API for OTel instrumentation. Allow users to configure…
dsessler7 Feb 9, 2025
38fc33a
Add instrumentation_scope.name and log.record.original attributes to …
dsessler7 Feb 9, 2025
3602c70
Add configurable collector (#4092)
benjaminjb Feb 12, 2025
f7e9625
Add shared functions for quoting shell words
cbandy Nov 4, 2024
d4483cc
Add a function for setting permission on directories
cbandy Feb 10, 2025
e6ea78b
Store pgAdmin log file positions in the logs directory
cbandy Feb 6, 2025
951fa40
Ensure Postgres and Patroni log directories are writable
cbandy Feb 10, 2025
88130ca
Ensure pgBackRest log directories are writable
cbandy Feb 11, 2025
8dbe427
Add a field specifying when to delete log files
cbandy Feb 14, 2025
1797f8f
Rotate PgBouncer logs using specified retention
dsessler7 Feb 11, 2025
8b87822
Document a Kubernetes bug with the duration format
cbandy Feb 18, 2025
85636a8
Add an API struct representing a single Secret value
cbandy Jan 15, 2025
ef1eae0
Allow more control over the arguments to pg_upgrade
cbandy Dec 9, 2024
510ddf4
Validate pg_upgrade versions at the API server
cbandy Feb 19, 2025
e4dfdf2
Add a validated field for Postgres parameters
cbandy Dec 20, 2024
e884806
Otel pgMonitor metrics (#4096)
tony-landreth Feb 21, 2025
00c9068
Add reload logic to collector container start script.
dsessler7 Feb 19, 2025
19a28f7
Add a test helper that unmarshals JSON and YAML
cbandy Feb 26, 2025
9977db2
If the OpenTelemetryLogs feature gate is set, tell patroni to log to …
dsessler7 Feb 26, 2025
bfd4160
Add resources from API to OTEL sidecar (#4104)
benjaminjb Feb 26, 2025
6ba9057
Change PostgresCluster.spec.config to a pointer
cbandy Feb 26, 2025
2a2fe9b
Calculate Postgres parameters in the controller
cbandy Feb 26, 2025
9018342
Rotate postgres logs according to retentionPeriod in spec.
dsessler7 Feb 20, 2025
d04885c
Clone embedded metrics variable to avoid continuous appending.
dsessler7 Feb 28, 2025
00a93f6
Add a script to help with bumping dependencies
cbandy Feb 28, 2025
6dbbf9b
Bump golang.org/x/crypto and golang.org/x/oauth2
cbandy Feb 28, 2025
b50bae9
Rotate pgbackrest (#4108)
benjaminjb Mar 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a validated field for Postgres parameters
The validation rules of Kubernetes 1.29 (Beta in 1.25) allow for this
kind of field.

Issue: PGO-313
  • Loading branch information
cbandy committed Feb 21, 2025
commit e4dfdf2d14b6f3fd9964500436bf6eae964c010f
Original file line number Diff line number Diff line change
Expand Up @@ -4370,6 +4370,7 @@ spec:
config:
properties:
files:
description: Files to mount under "/etc/postgres".
items:
description: |-
Projection that may be projected along with other supported volume types.
Expand Down Expand Up @@ -4688,6 +4689,54 @@ spec:
type: object
type: object
type: array
parameters:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
description: |-
Configuration parameters for the PostgreSQL server. Some values will
be reloaded without validation and some cause PostgreSQL to restart.
Some values cannot be changed at all.
More info: https://www.postgresql.org/docs/current/runtime-config.html
maxProperties: 50
type: object
x-kubernetes-map-type: granular
x-kubernetes-validations:
- message: 'cannot change PGDATA path: config_file, data_directory'
rule: '!has(self.config_file) && !has(self.data_directory)'
- message: cannot change external_pid_file
rule: '!has(self.external_pid_file)'
- message: 'cannot change authentication path: hba_file, ident_file'
rule: '!has(self.hba_file) && !has(self.ident_file)'
- message: 'network connectivity is always enabled: listen_addresses'
rule: '!has(self.listen_addresses)'
- message: change port using .spec.port instead
rule: '!has(self.port)'
- message: TLS is always enabled
rule: '!has(self.ssl) && !self.exists(k, k.startsWith("ssl_"))'
- message: domain socket paths cannot be changed
rule: '!self.exists(k, k.startsWith("unix_socket_"))'
- message: wal_level must be "replica" or higher
rule: '!has(self.wal_level) || self.wal_level in ["logical"]'
- message: wal_log_hints are always enabled
rule: '!has(self.wal_log_hints)'
- rule: '!has(self.archive_mode) && !has(self.archive_command)
&& !has(self.restore_command)'
- rule: '!has(self.recovery_target) && !self.exists(k, k.startsWith("recovery_target_"))'
- message: hot_standby is always enabled
rule: '!has(self.hot_standby)'
- rule: '!has(self.synchronous_standby_names)'
- rule: '!has(self.primary_conninfo) && !has(self.primary_slot_name)'
- message: delayed replication is not supported at this time
rule: '!has(self.recovery_min_apply_delay)'
- message: cluster_name is derived from the PostgresCluster name
rule: '!has(self.cluster_name)'
- message: disabling logging_collector is unsafe
rule: '!has(self.logging_collector)'
- message: log_file_mode cannot be changed
rule: '!has(self.log_file_mode)'
type: object
customReplicationTLSSecret:
description: |-
Expand Down
20 changes: 12 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ func defaultFromEnv(value, key string) string {
// FetchKeyCommand returns the fetch_key_cmd value stored in the encryption_key_command
// variable used to enable TDE.
func FetchKeyCommand(spec *v1beta1.PostgresClusterSpec) string {
if parameters := spec.Config.Parameters; parameters != nil {
if v, ok := parameters["encryption_key_command"]; ok {
return v.String()
}
}

if spec.Patroni != nil {
if spec.Patroni.DynamicConfiguration != nil {
configuration := spec.Patroni.DynamicConfiguration
if configuration != nil {
if postgresql, ok := configuration["postgresql"].(map[string]any); ok {
if parameters, ok := postgresql["parameters"].(map[string]any); ok {
if parameters["encryption_key_command"] != nil {
return fmt.Sprintf("%s", parameters["encryption_key_command"])
}
if configuration := spec.Patroni.DynamicConfiguration; configuration != nil {
if postgresql, ok := configuration["postgresql"].(map[string]any); ok {
if parameters, ok := postgresql["parameters"].(map[string]any); ok {
if parameters["encryption_key_command"] != nil {
return fmt.Sprintf("%s", parameters["encryption_key_command"])
}
}
}
}
}

return ""
}

Expand Down
149 changes: 98 additions & 51 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,115 @@ import (
)

func TestFetchKeyCommand(t *testing.T) {

spec1 := v1beta1.PostgresClusterSpec{}
assert.Assert(t, FetchKeyCommand(&spec1) == "")

spec2 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{},
}
assert.Assert(t, FetchKeyCommand(&spec2) == "")

spec3 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{},
},
}
assert.Assert(t, FetchKeyCommand(&spec3) == "")

spec4 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{
"postgresql": map[string]any{},
t.Run("missing", func(t *testing.T) {
spec1 := v1beta1.PostgresClusterSpec{}
assert.Assert(t, FetchKeyCommand(&spec1) == "")

spec2 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{},
}
assert.Assert(t, FetchKeyCommand(&spec2) == "")

spec3 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{},
},
},
}
assert.Assert(t, FetchKeyCommand(&spec4) == "")
}
assert.Assert(t, FetchKeyCommand(&spec3) == "")

spec5 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{
"postgresql": map[string]any{
"parameters": map[string]any{},
spec4 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{
"postgresql": map[string]any{},
},
},
},
}
assert.Assert(t, FetchKeyCommand(&spec5) == "")

spec6 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{
"postgresql": map[string]any{
"parameters": map[string]any{
"encryption_key_command": "",
}
assert.Assert(t, FetchKeyCommand(&spec4) == "")

spec5 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{
"postgresql": map[string]any{
"parameters": map[string]any{},
},
},
},
},
}
assert.Assert(t, FetchKeyCommand(&spec6) == "")

spec7 := v1beta1.PostgresClusterSpec{
Patroni: &v1beta1.PatroniSpec{
DynamicConfiguration: map[string]any{
"postgresql": map[string]any{
"parameters": map[string]any{
"encryption_key_command": "echo mykey",
}
assert.Assert(t, FetchKeyCommand(&spec5) == "")
})

t.Run("blank", func(t *testing.T) {
var spec1 v1beta1.PostgresClusterSpec
assert.NilError(t, yaml.Unmarshal([]byte(`{
patroni: {
dynamicConfiguration: {
postgresql: {
parameters: {
encryption_key_command: "",
},
},
},
},
},
}
assert.Assert(t, FetchKeyCommand(&spec7) == "echo mykey")
}`), &spec1))
assert.Equal(t, "", FetchKeyCommand(&spec1))

var spec2 v1beta1.PostgresClusterSpec
assert.NilError(t, yaml.Unmarshal([]byte(`{
config: {
parameters: {
encryption_key_command: "",
},
},
}`), &spec2))
assert.Equal(t, "", FetchKeyCommand(&spec2))
})

t.Run("exists", func(t *testing.T) {
var spec1 v1beta1.PostgresClusterSpec
assert.NilError(t, yaml.Unmarshal([]byte(`{
patroni: {
dynamicConfiguration: {
postgresql: {
parameters: {
encryption_key_command: "echo mykey",
},
},
},
},
}`), &spec1))
assert.Equal(t, "echo mykey", FetchKeyCommand(&spec1))

var spec2 v1beta1.PostgresClusterSpec
assert.NilError(t, yaml.Unmarshal([]byte(`{
config: {
parameters: {
encryption_key_command: "cat somefile",
},
},
}`), &spec2))
assert.Equal(t, "cat somefile", FetchKeyCommand(&spec2))
})

t.Run("config.parameters takes precedence", func(t *testing.T) {
var spec v1beta1.PostgresClusterSpec
assert.NilError(t, yaml.Unmarshal([]byte(`{
config: {
parameters: {
encryption_key_command: "cat somefile",
},
},
patroni: {
dynamicConfiguration: {
postgresql: {
parameters: {
encryption_key_command: "echo mykey",
},
},
},
},
}`), &spec))
assert.Equal(t, "cat somefile", FetchKeyCommand(&spec))
})
}

func TestPGAdminContainerImage(t *testing.T) {
Expand Down
18 changes: 15 additions & 3 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/yaml"

"github.com/crunchydata/postgres-operator/internal/config"
Expand Down Expand Up @@ -244,7 +245,11 @@ func DynamicConfiguration(
parameters[k] = v
}
}
// Override the above with mandatory parameters.
// Copy spec.config.parameters over spec.patroni...parameters.
for k, v := range spec.Config.Parameters {
parameters[k] = v
}
// Override all of the above with mandatory parameters.
if pgParameters.Mandatory != nil {
for k, v := range pgParameters.Mandatory.AsMap() {

Expand All @@ -254,8 +259,15 @@ func DynamicConfiguration(
// that out as well.
if k == "shared_preload_libraries" {
// Load mandatory libraries ahead of user-defined libraries.
if s, ok := parameters[k].(string); ok && len(s) > 0 {
v = v + "," + s
switch s := parameters[k].(type) {
case string:
if len(s) > 0 {
v = v + "," + s
}
case intstr.IntOrString:
if len(s.StrVal) > 0 {
v = v + "," + s.StrVal
}
}
// Load "citus" ahead of any other libraries.
// - https://github.com/citusdata/citus/blob/v12.0.0/src/backend/distributed/shared_library_init.c#L417-L419
Expand Down
Loading