@@ -45,10 +45,9 @@ func createRotateServerStoragePlan(ctx context.Context,
4545 return nil
4646 }
4747 var plan api.Plan
48- var canContinue = true
4948 status .Members .ForeachServerGroup (func (group api.ServerGroup , members api.MemberStatusList ) error {
5049 for _ , m := range members {
51- if ! plan .IsEmpty () && ! canContinue {
50+ if ! plan .IsEmpty () {
5251 // Only 1 change at a time
5352 continue
5453 }
@@ -74,9 +73,6 @@ func createRotateServerStoragePlan(ctx context.Context,
7473 }
7574
7675 if util .StringOrDefault (pvc .Spec .StorageClassName ) != storageClassName && storageClassName != "" {
77- // Do not append more than 1 operation if we replace storageClass
78- canContinue = false
79-
8076 // Storageclass has changed
8177 log .Info ().Str ("pod-name" , m .PodName ).
8278 Str ("pvc-storage-class" , util .StringOrDefault (pvc .Spec .StorageClassName )).
@@ -106,15 +102,8 @@ func createRotateServerStoragePlan(ctx context.Context,
106102 if requestedSize , ok := res [core .ResourceStorage ]; ok {
107103 if volumeSize , ok := pvc .Spec .Resources .Requests [core .ResourceStorage ]; ok {
108104 cmp := volumeSize .Cmp (requestedSize )
109- if cmp < 0 {
110- if groupSpec .VolumeResizeMode .Get () == api .PVCResizeModeRotate {
111- // Do not append more than 1 operation if we hard restart member
112- canContinue = false
113- }
114- plan = append (plan , pvcResizePlan (log , group , groupSpec , m .ID )... )
115- } else if cmp > 0 {
116- // Do not append more than 1 operation if we schrink volume
117- canContinue = false
105+ // Only schrink is possible
106+ if cmp > 0 {
118107
119108 if groupSpec .GetVolumeAllowShrink () && group == api .ServerGroupDBServers && ! m .Conditions .IsTrue (api .ConditionTypeMarkedToRemove ) {
120109 plan = append (plan , api .NewAction (api .ActionTypeMarkToRemoveMember , group , m .ID ))
@@ -133,6 +122,61 @@ func createRotateServerStoragePlan(ctx context.Context,
133122 return plan
134123}
135124
125+ // createRotateServerStorageResizePlan creates plan to resize storage
126+ func createRotateServerStorageResizePlan (ctx context.Context ,
127+ log zerolog.Logger , apiObject k8sutil.APIObject ,
128+ spec api.DeploymentSpec , status api.DeploymentStatus ,
129+ cachedStatus inspectorInterface.Inspector , context PlanBuilderContext ) api.Plan {
130+ var plan api.Plan
131+
132+ status .Members .ForeachServerGroup (func (group api.ServerGroup , members api.MemberStatusList ) error {
133+ for _ , m := range members {
134+ if m .Phase != api .MemberPhaseCreated {
135+ // Only make changes when phase is created
136+ continue
137+ }
138+ if m .PersistentVolumeClaimName == "" {
139+ // Plan is irrelevant without PVC
140+ continue
141+ }
142+ groupSpec := spec .GetServerGroupSpec (group )
143+
144+ if ! plan .IsEmpty () && groupSpec .VolumeResizeMode .Get () == api .PVCResizeModeRotate {
145+ // Only 1 change at a time
146+ return nil
147+ }
148+
149+ // Load PVC
150+ pvc , exists := cachedStatus .PersistentVolumeClaim (m .PersistentVolumeClaimName )
151+ if ! exists {
152+ log .Warn ().
153+ Str ("role" , group .AsRole ()).
154+ Str ("id" , m .ID ).
155+ Msg ("Failed to get PVC" )
156+ continue
157+ }
158+
159+ var res core.ResourceList
160+ if groupSpec .HasVolumeClaimTemplate () {
161+ res = groupSpec .GetVolumeClaimTemplate ().Spec .Resources .Requests
162+ } else {
163+ res = groupSpec .Resources .Requests
164+ }
165+ if requestedSize , ok := res [core .ResourceStorage ]; ok {
166+ if volumeSize , ok := pvc .Spec .Resources .Requests [core .ResourceStorage ]; ok {
167+ cmp := volumeSize .Cmp (requestedSize )
168+ if cmp < 0 {
169+ plan = append (plan , pvcResizePlan (log , group , groupSpec , m .ID )... )
170+ }
171+ }
172+ }
173+ }
174+ return nil
175+ })
176+
177+ return plan
178+ }
179+
136180func pvcResizePlan (log zerolog.Logger , group api.ServerGroup , groupSpec api.ServerGroupSpec , memberID string ) api.Plan {
137181 mode := groupSpec .VolumeResizeMode .Get ()
138182 switch mode {
0 commit comments