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
Change PostgresIdentifier to a type alias
The type existed to avoid schema repetition with controller-gen, but
recent versions can do that using aliases. This eliminates the need for
some conversions.
  • Loading branch information
cbandy committed Feb 11, 2025
commit fbb4f32daa38cc8388385ca1e47eb0b1211e8247
Original file line number Diff line number Diff line change
Expand Up @@ -17087,9 +17087,6 @@ spec:
database from this list does NOT revoke access. This field is ignored for
the "postgres" user.
items:
description: |-
PostgreSQL identifiers are limited in length but may contain any character.
More info: https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
maxLength: 63
minLength: 1
type: string
Expand Down
17 changes: 7 additions & 10 deletions internal/controller/postgrescluster/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
func (r *Reconciler) generatePostgresUserSecret(
cluster *v1beta1.PostgresCluster, spec *v1beta1.PostgresUserSpec, existing *corev1.Secret,
) (*corev1.Secret, error) {
username := string(spec.Name)
username := spec.Name
intent := &corev1.Secret{ObjectMeta: naming.PostgresUserSecret(cluster, username)}
intent.SetGroupVersionKind(corev1.SchemeGroupVersion.WithKind("Secret"))
initialize.Map(&intent.Data)
Expand Down Expand Up @@ -100,7 +100,7 @@ func (r *Reconciler) generatePostgresUserSecret(
// When a database has been specified, include it and a connection URI.
// - https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
if len(spec.Databases) > 0 {
database := string(spec.Databases[0])
database := spec.Databases[0]

intent.Data["dbname"] = []byte(database)
intent.Data["uri"] = []byte((&url.URL{
Expand Down Expand Up @@ -133,7 +133,7 @@ func (r *Reconciler) generatePostgresUserSecret(
intent.Data["pgbouncer-port"] = []byte(port)

if len(spec.Databases) > 0 {
database := string(spec.Databases[0])
database := spec.Databases[0]

intent.Data["pgbouncer-uri"] = []byte((&url.URL{
Scheme: "postgresql",
Expand Down Expand Up @@ -216,9 +216,7 @@ func (r *Reconciler) reconcilePostgresDatabases(
}
} else {
for _, user := range cluster.Spec.Users {
for _, database := range user.Databases {
databases.Insert(string(database))
}
databases.Insert(user.Databases...)
}
}

Expand Down Expand Up @@ -379,18 +377,17 @@ func (r *Reconciler) reconcilePostgresUserSecrets(
r.Recorder.Event(cluster, corev1.EventTypeWarning, "InvalidUser",
allErrors.ToAggregate().Error())
} else {
identifier := v1beta1.PostgresIdentifier(cluster.Name)
specUsers = []v1beta1.PostgresUserSpec{{
Name: identifier,
Databases: []v1beta1.PostgresIdentifier{identifier},
Name: cluster.Name,
Databases: []string{cluster.Name},
}}
}
}

// Index user specifications by PostgreSQL user name.
userSpecs := make(map[string]*v1beta1.PostgresUserSpec, len(specUsers))
for i := range specUsers {
userSpecs[string(specUsers[i].Name)] = &specUsers[i]
userSpecs[specUsers[i].Name] = &specUsers[i]
}

secrets := &corev1.SecretList{}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/postgrescluster/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
}

// Present when specified.
spec.Databases = []v1beta1.PostgresIdentifier{"db1"}
spec.Databases = []string{"db1"}

secret, err = reconciler.generatePostgresUserSecret(cluster, &spec, nil)
assert.NilError(t, err)
Expand All @@ -180,7 +180,7 @@ func TestGeneratePostgresUserSecret(t *testing.T) {
}

// Only the first in the list.
spec.Databases = []v1beta1.PostgresIdentifier{"first", "asdf"}
spec.Databases = []string{"first", "asdf"}

secret, err = reconciler.generatePostgresUserSecret(cluster, &spec, nil)
assert.NilError(t, err)
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestGeneratePostgresUserSecret(t *testing.T) {

// Includes a URI when possible.
spec := *spec
spec.Databases = []v1beta1.PostgresIdentifier{"yes", "no"}
spec.Databases = []string{"yes", "no"}

secret, err = reconciler.generatePostgresUserSecret(cluster, &spec, nil)
assert.NilError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/pgadmin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ with create_app().app_context():`,
if err == nil {
err = encoder.Encode(map[string]interface{}{
"username": spec.Name,
"password": passwords[string(spec.Name)],
"password": passwords[spec.Name],
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pgadmin/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ with create_app().app_context():
[]v1beta1.PostgresUserSpec{
{
Name: "user-no-options",
Databases: []v1beta1.PostgresIdentifier{"db1"},
Databases: []string{"db1"},
},
{
Name: "user-no-databases",
Expand Down
8 changes: 4 additions & 4 deletions internal/postgres/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ CREATE TEMPORARY TABLE input (id serial, data json);
"databases": databases,
"options": options,
"username": spec.Name,
"verifier": verifiers[string(spec.Name)],
"verifier": verifiers[spec.Name],
})
}
}
Expand Down Expand Up @@ -194,9 +194,9 @@ func WriteUsersSchemasInPostgreSQL(ctx context.Context, exec Executor,
spec := users[i]

// We skip if the user has the name of a reserved schema
if RESERVED_SCHEMA_NAMES[string(spec.Name)] {
if RESERVED_SCHEMA_NAMES[spec.Name] {
log.V(1).Info("Skipping schema creation for user with reserved name",
"name", string(spec.Name))
"name", spec.Name)
continue
}

Expand Down Expand Up @@ -239,7 +239,7 @@ func WriteUsersSchemasInPostgreSQL(ctx context.Context, exec Executor,
}, "\n"),
map[string]string{
"databases": string(databases),
"username": string(spec.Name),
"username": spec.Name,

"ON_ERROR_STOP": "on", // Abort when any one statement fails.
"QUIET": "on", // Do not print successful commands to stdout.
Expand Down
10 changes: 5 additions & 5 deletions internal/postgres/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ COMMIT;`))
[]v1beta1.PostgresUserSpec{
{
Name: "user-no-options",
Databases: []v1beta1.PostgresIdentifier{"db1"},
Databases: []string{"db1"},
},
{
Name: "user-no-databases",
Expand Down Expand Up @@ -175,7 +175,7 @@ COMMIT;`))
[]v1beta1.PostgresUserSpec{
{
Name: "postgres",
Databases: []v1beta1.PostgresIdentifier{"all", "ignored"},
Databases: []string{"all", "ignored"},
Options: "NOLOGIN CONNECTION LIMIT 0",
},
},
Expand Down Expand Up @@ -213,18 +213,18 @@ func TestWriteUsersSchemasInPostgreSQL(t *testing.T) {
[]v1beta1.PostgresUserSpec{
{
Name: "user-single-db",
Databases: []v1beta1.PostgresIdentifier{"db1"},
Databases: []string{"db1"},
},
{
Name: "user-no-databases",
},
{
Name: "user-multi-dbs",
Databases: []v1beta1.PostgresIdentifier{"db1", "db2"},
Databases: []string{"db1", "db2"},
},
{
Name: "public",
Databases: []v1beta1.PostgresIdentifier{"db3"},
Databases: []string{"db3"},
},
},
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

package v1beta1

// ---
// PostgreSQL identifiers are limited in length but may contain any character.
// More info: https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
//
// - https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=63
type PostgresIdentifier string
type PostgresIdentifier = string

type PostgresPasswordSpec struct {
// Type of password to generate. Defaults to ASCII. Valid options are ASCII
Expand All @@ -23,6 +23,7 @@ type PostgresPasswordSpec struct {
//
// +kubebuilder:default=ASCII
// +kubebuilder:validation:Enum={ASCII,AlphaNumeric}
// +required
Type string `json:"type"`
}

Expand All @@ -33,27 +34,32 @@ const (
)

type PostgresUserSpec struct {

// This value goes into the name of a corev1.Secret and a label value, so
// it must match both IsDNS1123Subdomain and IsValidLabelValue. The pattern
// below is IsDNS1123Subdomain without any dots, U+002E.

// The name of this PostgreSQL user. The value may contain only lowercase
// letters, numbers, and hyphen so that it fits into Kubernetes metadata.
// ---
// This value goes into the name of a corev1.Secret and a label value, so
// it must match both IsDNS1123Subdomain and IsValidLabelValue.
// - https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsDNS1123Subdomain
// - https://pkg.go.dev/k8s.io/apimachinery/pkg/util/validation#IsValidLabelValue
//
// This is IsDNS1123Subdomain without any dots, U+002E:
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
// +kubebuilder:validation:Type=string
//
// +required
Name PostgresIdentifier `json:"name"`

// Databases to which this user can connect and create objects. Removing a
// database from this list does NOT revoke access. This field is ignored for
// the "postgres" user.
// ---
// +listType=set
// +optional
Databases []PostgresIdentifier `json:"databases,omitempty"`

// ALTER ROLE options except for PASSWORD. This field is ignored for the
// "postgres" user.
// More info: https://www.postgresql.org/docs/current/role-attributes.html
// ---
// +kubebuilder:validation:MaxLength=200
// +kubebuilder:validation:Pattern=`^[^;]*$`
// +kubebuilder:validation:XValidation:rule=`!self.matches("(?i:PASSWORD)")`,message="cannot assign password"
Expand All @@ -62,6 +68,7 @@ type PostgresUserSpec struct {
Options string `json:"options,omitempty"`

// Properties of the password generated for this user.
// ---
// +optional
Password *PostgresPasswordSpec `json:"password,omitempty"`
}