Skip to content

Commit 23bb0bd

Browse files
committed
Add Disk Auto Grow for pgWAL volumes
This update adds the ability to automatically grow pg_wal PVCs. The AutoGrowVolumes feature gate must be enabled and the relevant volumes must include a Limit value. Once enabled, this feature tracks the current disk utilization and, when utilization reaches 75%, the disk request is updated to 150% of the observed value. At this point and beyond, the requested value will be tracked by CPK. The volume request can grow up to the configured limit value. Note: This change now treats limit values as authoritative regardless of the feature gate setting. However, the implementation also now allows limits to be updated after being set. Issue: PGO-1428
1 parent 1043bff commit 23bb0bd

File tree

14 files changed

+317
-45
lines changed

14 files changed

+317
-45
lines changed

.golangci.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ linters:
170170
text: >-
171171
deprecated: Use `RequeueAfter` instead
172172
173-
- linters: [unparam]
174-
path: internal/controller/postgrescluster/autogrow.go
175-
text: volumeType always receives \"pgData\"
176-
177173
# https://golangci-lint.run/usage/formatters
178174
formatters:
179175
enable:

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18632,6 +18632,11 @@ spec:
1863218632
type: string
1863318633
description: Desired Size of the pgData volume
1863418634
type: object
18635+
desiredPGWALVolume:
18636+
additionalProperties:
18637+
type: string
18638+
description: Desired Size of the pgWAL volume
18639+
type: object
1863518640
name:
1863618641
type: string
1863718642
readyReplicas:
@@ -37557,6 +37562,11 @@ spec:
3755737562
type: string
3755837563
description: Desired Size of the pgData volume
3755937564
type: object
37565+
desiredPGWALVolume:
37566+
additionalProperties:
37567+
type: string
37568+
description: Desired Size of the pgWAL volume
37569+
type: object
3756037570
name:
3756137571
type: string
3756237572
readyReplicas:

internal/controller/postgrescluster/autogrow.go

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ func (r *Reconciler) storeDesiredRequest(
5757
// determine if the appropriate volume limit is set
5858
limitSet := limitIsSet(cluster, volumeType, host)
5959

60-
if limitSet && current.Value() > previous.Value() {
60+
// if nil, volume does not exist
61+
if limitSet == nil {
62+
return ""
63+
}
64+
65+
if *limitSet && current.Value() > previous.Value() {
6166
r.Recorder.Eventf(cluster, corev1.EventTypeNormal, "VolumeAutoGrow",
6267
"%s volume expansion to %v requested for %s/%s.",
6368
volumeType, current.String(), cluster.Name, host)
@@ -74,34 +79,48 @@ func (r *Reconciler) storeDesiredRequest(
7479
}
7580

7681
// limitIsSet determines if the limit is set for a given volume type and returns
77-
// a corresponding boolean value
78-
func limitIsSet(cluster *v1beta1.PostgresCluster, volumeType, instanceSetName string) bool {
79-
80-
var limitSet bool
82+
// either a corresponding boolean value or nil if the volume is not defined.
83+
func limitIsSet(cluster *v1beta1.PostgresCluster, volumeType, instanceSetName string) *bool {
8184

8285
switch {
8386

84-
// Cycle through the instance sets to ensure the correct limit is identified.
87+
// For pgData and pgWAL volumes, cycle through the instance sets to ensure
88+
// the correct limit is identified.
8589
case volumeType == "pgData":
8690
for _, specInstance := range cluster.Spec.InstanceSets {
8791
if specInstance.Name == instanceSetName {
88-
limitSet = !specInstance.DataVolumeClaimSpec.Resources.Limits.Storage().IsZero()
92+
limitSet := !specInstance.DataVolumeClaimSpec.Resources.Limits.Storage().IsZero()
93+
return &limitSet
94+
}
95+
}
96+
case volumeType == "pgWAL":
97+
for _, specInstance := range cluster.Spec.InstanceSets {
98+
// return nil if volume is not defined
99+
if specInstance.Name == instanceSetName && specInstance.WALVolumeClaimSpec == nil {
100+
return nil
101+
}
102+
if specInstance.Name == instanceSetName && specInstance.WALVolumeClaimSpec != nil {
103+
limitSet := !specInstance.WALVolumeClaimSpec.Resources.Limits.Storage().IsZero()
104+
return &limitSet
89105
}
90106
}
91-
92107
// VolumeType for the repository host volumes should be in the form 'repoN'
93108
// where N is 1-4. As above, cycle through any defined repositories and ensure
94109
// the correct limit is identified.
95110
case strings.HasPrefix(volumeType, "repo"):
96111
for _, specRepo := range cluster.Spec.Backups.PGBackRest.Repos {
112+
// return nil if volume is not defined
113+
if specRepo.Name == volumeType && specRepo.Volume == nil {
114+
return nil
115+
}
97116
if specRepo.Name == volumeType && specRepo.Volume != nil {
98-
limitSet = !specRepo.Volume.VolumeClaimSpec.Resources.Limits.Storage().IsZero()
117+
limitSet := !specRepo.Volume.VolumeClaimSpec.Resources.Limits.Storage().IsZero()
118+
return &limitSet
99119
}
100120
}
101121
}
102-
// TODO: Add case for pgWAL
103122

104-
return limitSet
123+
return nil
105124

106125
}
107126

@@ -195,6 +214,24 @@ func getDesiredVolumeSize(cluster *v1beta1.PostgresCluster,
195214
}
196215
}
197216

217+
case volumeType == "pgWAL":
218+
for i := range cluster.Status.InstanceSets {
219+
if instanceSpecName == cluster.Status.InstanceSets[i].Name {
220+
for _, dpv := range cluster.Status.InstanceSets[i].DesiredPGWALVolume {
221+
if dpv != "" {
222+
desiredRequest, err := resource.ParseQuantity(dpv)
223+
if err == nil {
224+
if desiredRequest.Value() > volumeRequestSize.Value() {
225+
*volumeRequestSize = desiredRequest
226+
}
227+
} else {
228+
return dpv, err
229+
}
230+
}
231+
}
232+
}
233+
}
234+
198235
// VolumeType for the repository host volumes should be in the form 'repoN'
199236
// where N is 1-4. As above, cycle through any defined repositories and ensure
200237
// the correct limit is identified.
@@ -218,6 +255,5 @@ func getDesiredVolumeSize(cluster *v1beta1.PostgresCluster,
218255
}
219256
}
220257
}
221-
// TODO: Add case for pgWAL
222258
return "", nil
223259
}

0 commit comments

Comments
 (0)