@@ -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