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 an API struct representing a single Secret value
This adds validation to the recurring pattern of selecting a single
value from a Secret. Note that the "name" field is now required.

Secrets are best mounted as files, and the logic for translating these
references into volume projections is now consolidated in two exported
methods.
  • Loading branch information
cbandy committed Feb 21, 2025
commit 85636a8bbfdfa894400b16d6385a08143783f8ae
50 changes: 28 additions & 22 deletions config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -973,24 +973,27 @@ spec:
More info: https://www.pgadmin.org/docs/pgadmin4/latest/external_database.html
properties:
key:
description: The key of the secret to select from. Must be
a valid secret key.
description: Name of the data field within the Secret.
maxLength: 253
minLength: 1
pattern: ^[-._a-zA-Z0-9]+$
type: string
x-kubernetes-validations:
- message: cannot be "." or start with ".."
rule: self != "." && !self.startsWith("..")
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
description: Name of the Secret.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
optional:
description: Specify whether the Secret or its key must be
defined
description: Whether or not the Secret or its data must be
defined. Defaults to false.
type: boolean
required:
- key
- name
type: object
x-kubernetes-map-type: atomic
files:
Expand Down Expand Up @@ -1327,24 +1330,27 @@ spec:
More info: https://www.pgadmin.org/docs/pgadmin4/latest/ldap.html
properties:
key:
description: The key of the secret to select from. Must be
a valid secret key.
description: Name of the data field within the Secret.
maxLength: 253
minLength: 1
pattern: ^[-._a-zA-Z0-9]+$
type: string
x-kubernetes-validations:
- message: cannot be "." or start with ".."
rule: self != "." && !self.startsWith("..")
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
description: Name of the Secret.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
optional:
description: Specify whether the Secret or its key must be
defined
description: Whether or not the Secret or its data must be
defined. Defaults to false.
type: boolean
required:
- key
- name
type: object
x-kubernetes-map-type: atomic
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16895,24 +16895,27 @@ spec:
More info: https://www.pgadmin.org/docs/pgadmin4/latest/ldap.html
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
description: Name of the data field within the Secret.
maxLength: 253
minLength: 1
pattern: ^[-._a-zA-Z0-9]+$
type: string
x-kubernetes-validations:
- message: cannot be "." or start with ".."
rule: self != "." && !self.startsWith("..")
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
description: Name of the Secret.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
optional:
description: Specify whether the Secret or its key
must be defined
description: Whether or not the Secret or its data
must be defined. Defaults to false.
type: boolean
required:
- key
- name
type: object
x-kubernetes-map-type: atomic
settings:
Expand Down
26 changes: 6 additions & 20 deletions internal/controller/standalone_pgadmin/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,9 @@ func podConfigFiles(configmap *corev1.ConfigMap, pgadmin v1beta1.PGAdmin) []core

if pgadmin.Spec.Config.ConfigDatabaseURI != nil {
config = append(config, corev1.VolumeProjection{
Secret: &corev1.SecretProjection{
LocalObjectReference: pgadmin.Spec.Config.ConfigDatabaseURI.LocalObjectReference,
Optional: pgadmin.Spec.Config.ConfigDatabaseURI.Optional,
Items: []corev1.KeyToPath{
{
Key: pgadmin.Spec.Config.ConfigDatabaseURI.Key,
Path: configDatabaseURIPath,
},
},
},
Secret: initialize.Pointer(
pgadmin.Spec.Config.ConfigDatabaseURI.AsProjection(configDatabaseURIPath),
),
})
}

Expand All @@ -252,16 +245,9 @@ func podConfigFiles(configmap *corev1.ConfigMap, pgadmin v1beta1.PGAdmin) []core
// - https://www.pgadmin.org/docs/pgadmin4/development/enabling_ldap_authentication.html
if pgadmin.Spec.Config.LDAPBindPassword != nil {
config = append(config, corev1.VolumeProjection{
Secret: &corev1.SecretProjection{
LocalObjectReference: pgadmin.Spec.Config.LDAPBindPassword.LocalObjectReference,
Optional: pgadmin.Spec.Config.LDAPBindPassword.Optional,
Items: []corev1.KeyToPath{
{
Key: pgadmin.Spec.Config.LDAPBindPassword.Key,
Path: ldapFilePath,
},
},
},
Secret: initialize.Pointer(
pgadmin.Spec.Config.LDAPBindPassword.AsProjection(ldapFilePath),
),
})
}

Expand Down
14 changes: 4 additions & 10 deletions internal/pgadmin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

corev1 "k8s.io/api/core/v1"

"github.com/crunchydata/postgres-operator/internal/initialize"
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
)

Expand Down Expand Up @@ -94,16 +95,9 @@ func podConfigFiles(configmap *corev1.ConfigMap, spec v1beta1.PGAdminPodSpec) []
// - https://www.pgadmin.org/docs/pgadmin4/development/enabling_ldap_authentication.html
if spec.Config.LDAPBindPassword != nil {
config = append(config, corev1.VolumeProjection{
Secret: &corev1.SecretProjection{
LocalObjectReference: spec.Config.LDAPBindPassword.LocalObjectReference,
Optional: spec.Config.LDAPBindPassword.Optional,
Items: []corev1.KeyToPath{
{
Key: spec.Config.LDAPBindPassword.Key,
Path: ldapPasswordPath,
},
},
},
Secret: initialize.Pointer(
spec.Config.LDAPBindPassword.AsProjection(ldapPasswordPath),
),
})
}

Expand Down
6 changes: 3 additions & 3 deletions internal/pgadmin/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ volumes:
Name: "test",
}},
}}
cluster.Spec.UserInterface.PGAdmin.Config.LDAPBindPassword = &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
cluster.Spec.UserInterface.PGAdmin.Config.LDAPBindPassword = &v1beta1.OptionalSecretKeyRef{
SecretKeyRef: v1beta1.SecretKeyRef{
Name: "podtest",
Key: "podtestpw",
},
Key: "podtestpw",
}

call()
Expand Down
52 changes: 52 additions & 0 deletions pkg/apis/postgres-operator.crunchydata.com/v1beta1/config_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 - 2025 Crunchy Data Solutions, Inc.
//
// SPDX-License-Identifier: Apache-2.0

package v1beta1

import (
corev1 "k8s.io/api/core/v1"
)

// +structType=atomic
type OptionalSecretKeyRef struct {
SecretKeyRef `json:",inline"`

// Whether or not the Secret or its data must be defined. Defaults to false.
// +optional
Optional *bool `json:"optional,omitempty"`
}

// AsProjection returns a copy of this as a [corev1.SecretProjection].
func (in *OptionalSecretKeyRef) AsProjection(path string) corev1.SecretProjection {
out := in.SecretKeyRef.AsProjection(path)
if in.Optional != nil {
v := *in.Optional
out.Optional = &v
}
return out
}

// +structType=atomic
type SecretKeyRef struct {
// Name of the Secret.
// ---
// https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/core/validation#ValidateSecretName
// +required
Name DNS1123Subdomain `json:"name"`

// Name of the data field within the Secret.
// ---
// https://releases.k8s.io/v1.32.0/pkg/apis/core/validation/validation.go#L2867
// https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsConfigMapKey
// +required
Key ConfigDataKey `json:"key"`
}

// AsProjection returns a copy of this as a [corev1.SecretProjection].
func (in *SecretKeyRef) AsProjection(path string) corev1.SecretProjection {
var out corev1.SecretProjection
out.Name = in.Name
out.Items = []corev1.KeyToPath{{Key: in.Key, Path: path}}
return out
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2021 - 2025 Crunchy Data Solutions, Inc.
//
// SPDX-License-Identifier: Apache-2.0

package v1beta1_test

import (
"strings"
"testing"

"gotest.tools/v3/assert"
"sigs.k8s.io/yaml"

"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
)

func TestOptionalSecretKeyRefAsProjection(t *testing.T) {
t.Run("Null", func(t *testing.T) {
in := v1beta1.OptionalSecretKeyRef{}
in.Name, in.Key = "one", "two"

out := in.AsProjection("three")
b, err := yaml.Marshal(out)
assert.NilError(t, err)
assert.DeepEqual(t, string(b), strings.TrimSpace(`
items:
- key: two
path: three
name: one
`)+"\n")
})

t.Run("True", func(t *testing.T) {
True := true
in := v1beta1.OptionalSecretKeyRef{Optional: &True}
in.Name, in.Key = "one", "two"

out := in.AsProjection("three")
b, err := yaml.Marshal(out)
assert.NilError(t, err)
assert.DeepEqual(t, string(b), strings.TrimSpace(`
items:
- key: two
path: three
name: one
optional: true
`)+"\n")
})

t.Run("False", func(t *testing.T) {
False := false
in := v1beta1.OptionalSecretKeyRef{Optional: &False}
in.Name, in.Key = "one", "two"

out := in.AsProjection("three")
b, err := yaml.Marshal(out)
assert.NilError(t, err)
assert.DeepEqual(t, string(b), strings.TrimSpace(`
items:
- key: two
path: three
name: one
optional: false
`)+"\n")
})
}

func TestSecretKeyRefAsProjection(t *testing.T) {
in := v1beta1.SecretKeyRef{Name: "asdf", Key: "foobar"}
out := in.AsProjection("some-path")

b, err := yaml.Marshal(out)
assert.NilError(t, err)
assert.DeepEqual(t, string(b), strings.TrimSpace(`
items:
- key: foobar
path: some-path
name: asdf
`)+"\n")
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type PGAdminConfiguration struct {
// A Secret containing the value for the LDAP_BIND_PASSWORD setting.
// More info: https://www.pgadmin.org/docs/pgadmin4/latest/ldap.html
// +optional
LDAPBindPassword *corev1.SecretKeySelector `json:"ldapBindPassword,omitempty"`
LDAPBindPassword *OptionalSecretKeyRef `json:"ldapBindPassword,omitempty"`

// Settings for the pgAdmin server process. Keys should be uppercase and
// values must be constants.
Expand Down
19 changes: 19 additions & 0 deletions pkg/apis/postgres-operator.crunchydata.com/v1beta1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ import (
"k8s.io/kube-openapi/pkg/validation/strfmt"
)

// ---
// https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsConfigMapKey
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[-._a-zA-Z0-9]+$`
// +kubebuilder:validation:XValidation:rule=`self != "." && !self.startsWith("..")`,message=`cannot be "." or start with ".."`
type ConfigDataKey = string

// ---
// https://docs.k8s.io/concepts/overview/working-with-objects/names/#dns-subdomain-names
// https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsDNS1123Subdomain
// https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Format
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
type DNS1123Subdomain = string

// ---
// Duration represents a string accepted by the Kubernetes API in the "duration"
// [format]. This format extends the "duration" [defined by OpenAPI] by allowing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type StandalonePGAdminConfiguration struct {
// A Secret containing the value for the CONFIG_DATABASE_URI setting.
// More info: https://www.pgadmin.org/docs/pgadmin4/latest/external_database.html
// +optional
ConfigDatabaseURI *corev1.SecretKeySelector `json:"configDatabaseURI,omitempty"`
ConfigDatabaseURI *OptionalSecretKeyRef `json:"configDatabaseURI,omitempty"`

// Settings for the gunicorn server.
// More info: https://docs.gunicorn.org/en/latest/settings.html
Expand All @@ -32,7 +32,7 @@ type StandalonePGAdminConfiguration struct {
// A Secret containing the value for the LDAP_BIND_PASSWORD setting.
// More info: https://www.pgadmin.org/docs/pgadmin4/latest/ldap.html
// +optional
LDAPBindPassword *corev1.SecretKeySelector `json:"ldapBindPassword,omitempty"`
LDAPBindPassword *OptionalSecretKeyRef `json:"ldapBindPassword,omitempty"`

// Settings for the pgAdmin server process. Keys should be uppercase and
// values must be constants.
Expand Down
Loading