diff --git a/controllers/cluster_upgrade.go b/controllers/cluster_upgrade.go index 2f920f9a6d..1567f30130 100644 --- a/controllers/cluster_upgrade.go +++ b/controllers/cluster_upgrade.go @@ -385,10 +385,19 @@ func checkProjectedVolumeIsOutdated( status postgres.PostgresqlStatus, cluster *apiv1.Cluster, ) (rollout, error) { + isNilOrZero := func(vs *corev1.ProjectedVolumeSource) bool { + return vs == nil || len(vs.Sources) == 0 + } + // Check if there is a change in the projected volume configuration currentProjectedVolumeConfiguration := getProjectedVolumeConfigurationFromPod(*status.Pod) - desiredProjectedVolumeConfiguration := cluster.Spec.ProjectedVolumeTemplate.DeepCopy() + + // we do not need to raise a rollout if the desired and current projected volume source equal to zero-length or nil + if isNilOrZero(desiredProjectedVolumeConfiguration) && isNilOrZero(currentProjectedVolumeConfiguration) { + return rollout{}, nil + } + if desiredProjectedVolumeConfiguration != nil && desiredProjectedVolumeConfiguration.DefaultMode == nil { defaultMode := corev1.ProjectedVolumeSourceDefaultMode desiredProjectedVolumeConfiguration.DefaultMode = &defaultMode diff --git a/controllers/cluster_upgrade_test.go b/controllers/cluster_upgrade_test.go index ae55abc82a..a4d6b7b63f 100644 --- a/controllers/cluster_upgrade_test.go +++ b/controllers/cluster_upgrade_test.go @@ -421,6 +421,57 @@ var _ = Describe("Pod upgrade", Ordered, func() { Expect(rollout.required).To(BeTrue()) }) }) + + When("The projected volume changed", func() { + It("should not require rollout if projected volume is 0 length slice in cluster", + func(ctx SpecContext) { + cluster.Spec.ProjectedVolumeTemplate = &corev1.ProjectedVolumeSource{ + Sources: []corev1.VolumeProjection{}, + } + pod := specs.PodWithExistingStorage(cluster, 1) + status := postgres.PostgresqlStatus{ + Pod: pod, + IsPodReady: true, + ExecutableHash: "test", + } + + rollout := isPodNeedingRollout(ctx, status, &cluster) + Expect(rollout.reason).To(BeEmpty()) + Expect(rollout.required).To(BeFalse()) + }) + + It("should not require rollout if projected volume source is nil", + func(ctx SpecContext) { + cluster.Spec.ProjectedVolumeTemplate = &corev1.ProjectedVolumeSource{ + Sources: nil, + } + pod := specs.PodWithExistingStorage(cluster, 1) + status := postgres.PostgresqlStatus{ + Pod: pod, + IsPodReady: true, + ExecutableHash: "test", + } + + rollout := isPodNeedingRollout(ctx, status, &cluster) + Expect(rollout.reason).To(BeEmpty()) + Expect(rollout.required).To(BeFalse()) + }) + + It("should not require rollout if projected volume is nil", + func(ctx SpecContext) { + cluster.Spec.ProjectedVolumeTemplate = nil + pod := specs.PodWithExistingStorage(cluster, 1) + status := postgres.PostgresqlStatus{ + Pod: pod, + IsPodReady: true, + ExecutableHash: "test", + } + + rollout := isPodNeedingRollout(ctx, status, &cluster) + Expect(rollout.reason).To(BeEmpty()) + Expect(rollout.required).To(BeFalse()) + }) + }) }) var _ = Describe("Test pod rollout due to topology", func() {