Skip to content

Commit fe4aa54

Browse files
committed
Only store pgData and pgWAL request values when autogrow is enabled
The desiredPGDataVolume and desiredPGWALVolume status values should only be stored when a volume auto-grow event is imminent. This update adjusts the behavior so that this pattern is followed. Existing values will remain in place as needed if/when a Limit is removed. Issue: PGO-1428
1 parent a618814 commit fe4aa54

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

internal/controller/postgrescluster/autogrow.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (r *Reconciler) storeDesiredRequest(
6262
return ""
6363
}
6464

65+
// if the volume exists but the limit is not set, do not return the new value
66+
if !*limitSet {
67+
return desiredRequestBackup
68+
}
69+
6570
if *limitSet && current.Value() > previous.Value() {
6671
r.Recorder.Eventf(cluster, corev1.EventTypeNormal, "VolumeAutoGrow",
6772
"%s volume expansion to %v requested for %s/%s.",

internal/controller/postgrescluster/autogrow_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestStoreDesiredRequest(t *testing.T) {
116116
}, {
117117
tcName: "PGData-NoLimitNoEvent",
118118
Voltype: "pgData", host: "blue",
119-
desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "1Gi",
119+
desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "",
120120
expectedNumEvents: 0, expectedNumLogs: 0,
121121
}, {
122122
tcName: "PGData-BadBackupRequest",
@@ -145,7 +145,7 @@ func TestStoreDesiredRequest(t *testing.T) {
145145
}, {
146146
tcName: "PGWAL-NoLimitNoEvent",
147147
Voltype: "pgWAL", host: "blue",
148-
desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "1Gi",
148+
desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "",
149149
expectedNumEvents: 0, expectedNumLogs: 0,
150150
}, {
151151
tcName: "PGWAL-NoVolumeDefined",
@@ -179,7 +179,7 @@ func TestStoreDesiredRequest(t *testing.T) {
179179
}, {
180180
tcName: "Repo-NoLimitNoEvent",
181181
Voltype: "repo2", host: "repo-host",
182-
desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "1Gi",
182+
desiredRequest: "1Gi", desiredRequestBackup: "", expectedValue: "",
183183
expectedNumEvents: 0, expectedNumLogs: 0,
184184
}, {
185185
tcName: "Repo-NoRepoDefined",

internal/controller/postgrescluster/instance.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,26 @@ func (r *Reconciler) observeInstances(
371371
// If autogrow is enabled, determine the desired volume size for each instance
372372
// now that all the pod annotations have been collected. This final value will be
373373
// checked to ensure that the value from the annotations can be parsed to a valid
374-
// value. Otherwise the previous value, if available, will be used.
374+
// value. Otherwise the previous value, if available, will be used. If a limit is
375+
// not defined for the given volume and an empty string has been returned, nothing
376+
// will be stored in the status.
375377
if autogrow {
376378
for _, instance := range observed.bySet[name] {
377-
status.DesiredPGDataVolume[instance.Name] = r.storeDesiredRequest(ctx, cluster, "pgData",
378-
name, status.DesiredPGDataVolume[instance.Name], previousPGDataDesiredRequests[instance.Name])
379+
if pgDataRequest := r.storeDesiredRequest(
380+
ctx, cluster, "pgData", name,
381+
status.DesiredPGDataVolume[instance.Name],
382+
previousPGDataDesiredRequests[instance.Name],
383+
); pgDataRequest != "" {
384+
status.DesiredPGDataVolume[instance.Name] = pgDataRequest
385+
}
379386

380-
status.DesiredPGWALVolume[instance.Name] = r.storeDesiredRequest(ctx, cluster, "pgWAL",
381-
name, status.DesiredPGWALVolume[instance.Name], previousPGWALDesiredRequests[instance.Name])
387+
if pgWALRequest := r.storeDesiredRequest(
388+
ctx, cluster, "pgWAL", name,
389+
status.DesiredPGWALVolume[instance.Name],
390+
previousPGWALDesiredRequests[instance.Name],
391+
); pgWALRequest != "" {
392+
status.DesiredPGWALVolume[instance.Name] = pgWALRequest
393+
}
382394
}
383395
}
384396

0 commit comments

Comments
 (0)