From 60244fe497aba03b3e8aa1e46b7cf4788f25530c Mon Sep 17 00:00:00 2001 From: KR Ravindra <42912207+KR-Ravindra@users.noreply.github.com> Date: Wed, 9 Sep 2026 08:22:42 +0000 Subject: [PATCH] K8SPG-1099 clear inner PostgresCluster standby when spec.standby removed ToCrunchy() only assigned postgresCluster.Spec.Standby when the PerconaPGCluster had spec.standby set. Because ToCrunchy mutates the live PostgresCluster inside controllerutil.CreateOrUpdate, a standby block that was later removed from the PerconaPGCluster stayed on the inner object and the cluster never left standby mode. Reset Spec.Standby before the conditional assignment so the inner PostgresCluster always mirrors the PerconaPGCluster, and add a ToCrunchy unit test covering removal of spec.standby. --- .../v2/perconapgcluster_types.go | 1 + .../v2/perconapgcluster_types_test.go | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go index f6a0866f65..894e25b6e4 100644 --- a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go +++ b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go @@ -673,6 +673,7 @@ func (cr *PerconaPGCluster) ToCrunchy(ctx context.Context, postgresCluster *crun postgresCluster.Spec.Paused = cr.Spec.Unmanaged postgresCluster.Spec.Shutdown = cr.Spec.Pause + postgresCluster.Spec.Standby = nil if cr.Spec.Standby != nil { postgresCluster.Spec.Standby = cr.Spec.Standby.PostgresStandbySpec } diff --git a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go index ccba3157de..440e06bd32 100644 --- a/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go +++ b/pkg/apis/pgv2.percona.com/v2/perconapgcluster_types_test.go @@ -771,6 +771,47 @@ func TestPerconaPGCluster_ToCrunchy(t *testing.T) { assert.False(t, actual.Spec.Extensions.SetUser) }, }, + "clears standby on existing PostgresCluster when standby is removed": { + expectedPerconaPGCluster: &PerconaPGCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-cluster", + Namespace: "test-namespace", + }, + Spec: PerconaPGClusterSpec{ + CRVersion: version.Version(), + PostgresVersion: 18, + InstanceSets: PGInstanceSets{ + { + Name: "instance1", + Replicas: &[]int32{1}[0], + DataVolumeClaimSpec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, + }, + }, + }, + Backups: Backups{ + PGBackRest: PGBackRestArchive{ + Repos: []crunchyv1beta1.PGBackRestRepo{}, + }, + }, + }, + }, + inputPostgresCluster: &crunchyv1beta1.PostgresCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-cluster", + Namespace: "test-namespace", + }, + Spec: crunchyv1beta1.PostgresClusterSpec{ + Standby: &crunchyv1beta1.PostgresStandbySpec{ + Enabled: true, + RepoName: "repo1", + }, + }, + }, + assertClusterFunc: func(t *testing.T, actual *crunchyv1beta1.PostgresCluster, _ *PerconaPGCluster) { + assert.Nil(t, actual.Spec.Standby) + }, + }, } for testName, tt := range tests {