Skip to content
Open
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
6 changes: 5 additions & 1 deletion internal/controller/postgrescluster/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ func testCluster() *v1beta1.PostgresCluster {
},
Spec: v1beta1.PostgresClusterSpec{
PostgresVersion: 13,
Image: CrunchyPostgresHAImage,
Metadata: &v1beta1.Metadata{
Labels: map[string]string{"env-label": "test-label-value"},
Annotations: map[string]string{"env-annotation": "test-annotation-value"},
},
Image: CrunchyPostgresHAImage,
ImagePullSecrets: []corev1.LocalObjectReference{{
Name: "myImagePullSecret"},
},
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/postgrescluster/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (r *Reconciler) reconcileRootCertificate(
intent.Namespace, intent.Name = cluster.Namespace, naming.RootCertSecret
intent.Data = make(map[string][]byte)
intent.OwnerReferences = existing.OwnerReferences
intent.Annotations = naming.Merge(cluster.Spec.Metadata.GetAnnotationsOrNil())
intent.Labels = naming.Merge(cluster.Spec.Metadata.GetLabelsOrNil())

// A root secret is scoped to the namespace where postgrescluster(s)
// are deployed. For operator deployments with postgresclusters in more than
Expand Down
20 changes: 20 additions & 0 deletions internal/controller/postgrescluster/pki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ func TestReconcileCerts(t *testing.T) {
assert.DeepEqual(t, *fromSecret, initialRoot.Certificate)
})

t.Run("check root CA secret labels", func(t *testing.T) {
err := tClient.Get(ctx, client.ObjectKeyFromObject(rootSecret), rootSecret)
assert.NilError(t, err)

assert.Check(t, len(rootSecret.Labels) == 1, "root CA secret labels not set")

expectedLabel := map[string]string{"env-label": "test-label-value"}
assert.DeepEqual(t, rootSecret.Labels, expectedLabel)
})

t.Run("check root CA secret annotations", func(t *testing.T) {
err := tClient.Get(ctx, client.ObjectKeyFromObject(rootSecret), rootSecret)
assert.NilError(t, err)

assert.Check(t, len(rootSecret.Annotations) == 1, "root CA secret annotations not set")

expectedAnnotation := map[string]string{"env-annotation": "test-annotation-value"}
assert.DeepEqual(t, rootSecret.Annotations, expectedAnnotation)
})

t.Run("root certificate changes", func(t *testing.T) {
// force the generation of a new root cert
// create an empty secret and apply the change
Expand Down