Skip to content

Commit 163dbaf

Browse files
leonardocearmru
andauthored
fix: imperative restart should rollout the primary pod (cloudnative-pg#7122)
This patch updates the operator to create a new Pod for the primary instance when an imperative restart is requested. Previously, if `primaryUpdateMethod` was set to `restart`, the operator would recreate the replica Pods but only perform an in-place restart of the primary Pod. This approach could lead to inconsistencies between the definitions of the primary and the replica Pods, as only the replicas were fully recreated. Closes cloudnative-pg#7120 Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com> Co-authored-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
1 parent c112c8e commit 163dbaf

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

internal/controller/cluster_upgrade.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ func isPodNeedingRollout(
352352
}
353353

354354
checkers := map[string]rolloutChecker{
355-
"pod has missing PVCs": checkHasMissingPVCs,
356-
"pod has PVC requiring resizing": checkHasResizingPVC,
357-
"pod projected volume is outdated": checkProjectedVolumeIsOutdated,
358-
"pod image is outdated": checkPodImageIsOutdated,
359-
"cluster has newer restart annotation": checkClusterHasNewerRestartAnnotation,
355+
"pod has missing PVCs": checkHasMissingPVCs,
356+
"pod has PVC requiring resizing": checkHasResizingPVC,
357+
"pod projected volume is outdated": checkProjectedVolumeIsOutdated,
358+
"pod image is outdated": checkPodImageIsOutdated,
359+
"cluster has different restart annotation": checkClusterHasDifferentRestartAnnotation,
360360
}
361361

362362
podRollout := applyCheckers(checkers)
@@ -544,19 +544,15 @@ func checkHasMissingPVCs(pod *corev1.Pod, cluster *apiv1.Cluster) (rollout, erro
544544
return rollout{}, nil
545545
}
546546

547-
func checkClusterHasNewerRestartAnnotation(pod *corev1.Pod, cluster *apiv1.Cluster) (rollout, error) {
548-
// check if pod needs to be restarted because of some config requiring it
549-
// or if the cluster have been explicitly restarted
550-
// If the cluster has been restarted and we are working with a Pod
551-
// which has not been restarted yet, or restarted at a different
552-
// time, let's restart it.
547+
func checkClusterHasDifferentRestartAnnotation(pod *corev1.Pod, cluster *apiv1.Cluster) (rollout, error) {
548+
// If the pod restart value doesn't match with the one contained in the cluster, restart the pod.
553549
if clusterRestart, ok := cluster.Annotations[utils.ClusterRestartAnnotationName]; ok {
554550
podRestart := pod.Annotations[utils.ClusterRestartAnnotationName]
555551
if clusterRestart != podRestart {
556552
return rollout{
557553
required: true,
558554
reason: "cluster has been explicitly restarted via annotation",
559-
canBeInPlace: true,
555+
canBeInPlace: false,
560556
}, nil
561557
}
562558
}

internal/controller/cluster_upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var _ = Describe("Pod upgrade", Ordered, func() {
104104
rollout := isInstanceNeedingRollout(ctx, status, &clusterRestart)
105105
Expect(rollout.required).To(BeTrue())
106106
Expect(rollout.reason).To(Equal("cluster has been explicitly restarted via annotation"))
107-
Expect(rollout.canBeInPlace).To(BeTrue())
107+
Expect(rollout.canBeInPlace).To(BeFalse())
108108
Expect(rollout.needsChangeOperandImage).To(BeFalse())
109109
Expect(rollout.needsChangeOperatorImage).To(BeFalse())
110110

0 commit comments

Comments
 (0)