Repository: cloudnative-pg/cloudnative-pg

Issue:
[Bug]: race in tablespaces e2e tests
### Is there an existing issue already for this bug?

- [x] I have searched for an existing issue, and could not find anything. I believe this is a new bug.

### I have read the troubleshooting guide

- [x] I have read the troubleshooting guide and I think this is a new bug.

### I am running a supported version of CloudNativePG

- [x] I have read the troubleshooting guide and I think this is a new bug.

### Contact Details

_No response_

### Version

trunk (main)

### What version of Kubernetes are you using?

1.32

### What is your Kubernetes environment?

Self-managed: kind (evaluation)

### How did you install the operator?

YAML manifest

### What happened?

In https://github.com/cloudnative-pg/cloudnative-pg/blob/4ce21b89ef7e8dda8c1f2e671ba732de49b1c42a/tests/e2e/tablespaces_test.go#L138-L147 we check in a single attempt that the owner is updated after seeing the tablespace marked as reconciled. However, it is possible that the status is not yet up to date, so we rush to the check and fail it.

### Cluster resource

```shell

```

### Relevant log output

```shell

```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Discussion:

Solution patch:
diff --git a/internal/controller/cluster_upgrade.go b/internal/controller/cluster_upgrade.go
index dfcc54dc..b34ad064 100644
--- a/internal/controller/cluster_upgrade.go
+++ b/internal/controller/cluster_upgrade.go
@@ -352,11 +352,11 @@ func isPodNeedingRollout(
 	}
 
 	checkers := map[string]rolloutChecker{
-		"pod has missing PVCs":                 checkHasMissingPVCs,
-		"pod has PVC requiring resizing":       checkHasResizingPVC,
-		"pod projected volume is outdated":     checkProjectedVolumeIsOutdated,
-		"pod image is outdated":                checkPodImageIsOutdated,
-		"cluster has newer restart annotation": checkClusterHasNewerRestartAnnotation,
+		"pod has missing PVCs":                     checkHasMissingPVCs,
+		"pod has PVC requiring resizing":           checkHasResizingPVC,
+		"pod projected volume is outdated":         checkProjectedVolumeIsOutdated,
+		"pod image is outdated":                    checkPodImageIsOutdated,
+		"cluster has different restart annotation": checkClusterHasDifferentRestartAnnotation,
 	}
 
 	podRollout := applyCheckers(checkers)
@@ -544,19 +544,15 @@ func checkHasMissingPVCs(pod *corev1.Pod, cluster *apiv1.Cluster) (rollout, erro
 	return rollout{}, nil
 }
 
-func checkClusterHasNewerRestartAnnotation(pod *corev1.Pod, cluster *apiv1.Cluster) (rollout, error) {
-	// check if pod needs to be restarted because of some config requiring it
-	// or if the cluster have been explicitly restarted
-	// If the cluster has been restarted and we are working with a Pod
-	// which has not been restarted yet, or restarted at a different
-	// time, let's restart it.
+func checkClusterHasDifferentRestartAnnotation(pod *corev1.Pod, cluster *apiv1.Cluster) (rollout, error) {
+	// If the pod restart value doesn't match with the one contained in the cluster, restart the pod.
 	if clusterRestart, ok := cluster.Annotations[utils.ClusterRestartAnnotationName]; ok {
 		podRestart := pod.Annotations[utils.ClusterRestartAnnotationName]
 		if clusterRestart != podRestart {
 			return rollout{
 				required:     true,
 				reason:       "cluster has been explicitly restarted via annotation",
-				canBeInPlace: true,
+				canBeInPlace: false,
 			}, nil
 		}
 	}



Test patch:
diff --git a/internal/controller/cluster_upgrade_test.go b/internal/controller/cluster_upgrade_test.go
index a1540166..106cadca 100644
--- a/internal/controller/cluster_upgrade_test.go
+++ b/internal/controller/cluster_upgrade_test.go
@@ -104,7 +104,7 @@ var _ = Describe("Pod upgrade", Ordered, func() {
 		rollout := isInstanceNeedingRollout(ctx, status, &clusterRestart)
 		Expect(rollout.required).To(BeTrue())
 		Expect(rollout.reason).To(Equal("cluster has been explicitly restarted via annotation"))
-		Expect(rollout.canBeInPlace).To(BeTrue())
+		Expect(rollout.canBeInPlace).To(BeFalse())
 		Expect(rollout.needsChangeOperandImage).To(BeFalse())
 		Expect(rollout.needsChangeOperatorImage).To(BeFalse())