@@ -17,9 +17,8 @@ import (
1717)
1818
1919var (
20- volBindingMode = storagev1 .VolumeBindingWaitForFirstConsumer
21- reclaimPolicy = corev1 .PersistentVolumeReclaimDelete
22- allowVolumeExpansion = false
20+ volBindingMode = storagev1 .VolumeBindingWaitForFirstConsumer
21+ reclaimPolicy = corev1 .PersistentVolumeReclaimDelete
2322)
2423
2524func (s syncer ) Run (ctx context.Context ) error {
@@ -85,6 +84,11 @@ func (s syncer) Run(ctx context.Context) error {
8584 }
8685 }
8786
87+ if s .volumeExpansion {
88+ allowVolumeExpansion := s .volumeExpansion
89+ log .Printf ("Setting allowVolumeExpasion to %t..." , allowVolumeExpansion )
90+ }
91+
8892 if len (errs ) == 0 {
8993 return nil
9094 }
@@ -123,7 +127,7 @@ func (s syncer) syncOffering(ctx context.Context, offering *cloudstack.DiskOffer
123127 Provisioner : driver .DriverName ,
124128 VolumeBindingMode : & volBindingMode ,
125129 ReclaimPolicy : & reclaimPolicy ,
126- AllowVolumeExpansion : & allowVolumeExpansion ,
130+ AllowVolumeExpansion : & s . volumeExpansion ,
127131 Parameters : map [string ]string {
128132 driver .DiskOfferingKey : offering .Id ,
129133 },
@@ -134,9 +138,20 @@ func (s syncer) syncOffering(ctx context.Context, offering *cloudstack.DiskOffer
134138 return "" , err
135139 }
136140
141+ // Check and update AllowVolumeExpansion if necessary
142+ if sc .AllowVolumeExpansion == nil || * sc .AllowVolumeExpansion != s .volumeExpansion {
143+ log .Printf ("Updating AllowVolumeExpansion for storage class %s" , sc .Name )
144+ sc .AllowVolumeExpansion = & s .volumeExpansion
145+
146+ _ , err = s .k8sClient .StorageV1 ().StorageClasses ().Update (ctx , sc , metav1.UpdateOptions {})
147+ if err != nil {
148+ return "" , fmt .Errorf ("failed to update AllowVolumeExpansion for storage class %s: %w" , sc .Name , err )
149+ }
150+ }
151+
137152 // Storage class already exists
138153
139- err = checkStorageClass (sc , offering .Id )
154+ err = checkStorageClass (sc , offering .Id , s . volumeExpansion )
140155 if err != nil {
141156 // Updates to provisioner, reclaimpolicy, volumeBindingMode and parameters are forbidden
142157 log .Printf ("Storage class %s exists but it not compatible." , name )
@@ -159,7 +174,7 @@ func (s syncer) syncOffering(ctx context.Context, offering *cloudstack.DiskOffer
159174 return name , nil
160175}
161176
162- func checkStorageClass (sc * storagev1.StorageClass , expectedOfferingID string ) error {
177+ func checkStorageClass (sc * storagev1.StorageClass , expectedOfferingID string , expectedVolumeExpansion bool ) error {
163178 errs := make ([]error , 0 )
164179 diskOfferingID , ok := sc .Parameters [driver .DiskOfferingKey ]
165180 if ! ok {
@@ -174,8 +189,8 @@ func checkStorageClass(sc *storagev1.StorageClass, expectedOfferingID string) er
174189 if sc .VolumeBindingMode == nil || * sc .VolumeBindingMode != volBindingMode {
175190 errs = append (errs , errors .New ("wrong VolumeBindingMode" ))
176191 }
177- if sc .AllowVolumeExpansion == nil || * sc .AllowVolumeExpansion != allowVolumeExpansion {
178- errs = append (errs , errors . New ("wrong AllowVolumeExpansion" ))
192+ if sc .AllowVolumeExpansion == nil || * sc .AllowVolumeExpansion != expectedVolumeExpansion {
193+ errs = append (errs , fmt . Errorf ("wrong AllowVolumeExpansion for storage class %s" , sc . Name ))
179194 }
180195
181196 if len (errs ) > 0 {
0 commit comments