Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions e2e-tests/tests/init-deploy/05-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ metadata:
kind: PostgresCluster
name: init-deploy
---
apiVersion: v1
kind: Endpoints
metadata:
labels:
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/patroni: init-deploy-ha
test-label: test
name: init-deploy-ha
---
apiVersion: v1
kind: Endpoints
metadata:
labels:
postgres-operator.crunchydata.com/cluster: init-deploy
postgres-operator.crunchydata.com/patroni: init-deploy-ha
test-label: test
name: init-deploy-ha-config
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down
10 changes: 7 additions & 3 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func clusterYAML(
cluster *v1beta1.PostgresCluster,
pgHBAs postgres.HBAs, pgParameters postgres.Parameters,
) (string, error) {

labels := map[string]string{naming.LabelCluster: cluster.Name}
if cluster.CompareVersion("2.9.0") >= 0 {
labels = naming.Merge(cluster.Spec.Metadata.GetLabelsOrNil(), labels)
}

root := map[string]any{
// The cluster identifier. This value cannot change during the cluster's
// lifetime.
Expand All @@ -65,9 +71,7 @@ func clusterYAML(
// In addition to "scope_label" above, Patroni will add the following to
// every object it creates. It will also use these as filters when doing
// any lookups.
"labels": map[string]string{
naming.LabelCluster: cluster.Name,
},
"labels": labels,
},

"postgresql": map[string]any{
Expand Down
34 changes: 34 additions & 0 deletions internal/patroni/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
"sigs.k8s.io/yaml"

"github.com/percona/percona-postgresql-operator/v2/internal/initialize"
"github.com/percona/percona-postgresql-operator/v2/internal/naming"
"github.com/percona/percona-postgresql-operator/v2/internal/postgres"
"github.com/percona/percona-postgresql-operator/v2/internal/testing/cmp"
"github.com/percona/percona-postgresql-operator/v2/internal/testing/require"
pNaming "github.com/percona/percona-postgresql-operator/v2/percona/naming"
"github.com/percona/percona-postgresql-operator/v2/percona/version"
"github.com/percona/percona-postgresql-operator/v2/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
)

Expand Down Expand Up @@ -86,6 +88,38 @@ watchdog:
`)+"\n")
})

t.Run("metadata labels propagated to labels", func(t *testing.T) {
cluster := new(v1beta1.PostgresCluster)
err := cluster.Default(context.Background(), nil)
assert.NilError(t, err)
cluster.Namespace = "some-namespace"
cluster.Name = "cluster-name"
cluster.Labels = map[string]string{
naming.LabelVersion: version.Version(),
}
cluster.Spec.Metadata = &v1beta1.Metadata{
Labels: map[string]string{
"example.com/env": "production",
"example.com/owner": "team-a",
},
}

data, err := clusterYAML(cluster, postgres.HBAs{}, postgres.Parameters{})
assert.NilError(t, err)

var parsed map[string]any
assert.NilError(t, yaml.Unmarshal([]byte(data), &parsed))

k8sSection, ok := parsed["kubernetes"].(map[string]any)
assert.Assert(t, ok, "expected kubernetes section")
labels, ok := k8sSection["labels"].(map[string]any)
assert.Assert(t, ok, "expected kubernetes.labels section")

assert.Equal(t, labels["example.com/env"], "production")
assert.Equal(t, labels["example.com/owner"], "team-a")
assert.Equal(t, labels["postgres-operator.crunchydata.com/cluster"], "cluster-name")
})

t.Run(">PG10", func(t *testing.T) {
cluster := new(v1beta1.PostgresCluster)
err := cluster.Default(context.Background(), nil)
Expand Down
1 change: 0 additions & 1 deletion percona/controller/pgbackup/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pgbackup

import (
"context"
"fmt"
"path"
"slices"
"time"
Expand Down
Loading