@@ -31,60 +31,72 @@ import (
3131)
3232
3333// createRotateServerStorageResizePlan creates plan to resize storage
34- func (r * Reconciler ) createRotateServerStorageResizePlan (ctx context.Context , apiObject k8sutil.APIObject ,
34+ func (r * Reconciler ) createRotateServerStorageResizePlanRuntime (ctx context.Context , apiObject k8sutil.APIObject ,
3535 spec api.DeploymentSpec , status api.DeploymentStatus ,
3636 context PlanBuilderContext ) api.Plan {
37+ return r .createRotateServerStorageResizePlanInternal (spec , status , context , api .PVCResizeModeRuntime )
38+ }
39+
40+ func (r * Reconciler ) createRotateServerStorageResizePlanRotate (ctx context.Context , apiObject k8sutil.APIObject ,
41+ spec api.DeploymentSpec , status api.DeploymentStatus ,
42+ context PlanBuilderContext ) api.Plan {
43+ return r .createRotateServerStorageResizePlanInternal (spec , status , context , api .PVCResizeModeRotate )
44+ }
45+
46+ func (r * Reconciler ) createRotateServerStorageResizePlanInternal (spec api.DeploymentSpec , status api.DeploymentStatus , context PlanBuilderContext , mode api.PVCResizeMode ) api.Plan {
3747 var plan api.Plan
3848
39- status .Members .ForeachServerGroup (func (group api.ServerGroup , members api.MemberStatusList ) error {
40- for _ , m := range members {
41- cache , ok := context .ACS ().ClusterCache (m .ClusterID )
42- if ! ok {
43- // Do not work without cache
44- continue
45- }
46- if m .Phase != api .MemberPhaseCreated {
47- // Only make changes when phase is created
48- continue
49- }
50- if m .PersistentVolumeClaimName == "" {
51- // Plan is irrelevant without PVC
52- continue
53- }
54- groupSpec := spec .GetServerGroupSpec (group )
49+ for _ , member := range status .Members .AsList () {
50+ cache , ok := context .ACS ().ClusterCache (member .Member .ClusterID )
51+ if ! ok {
52+ // Do not work without cache
53+ continue
54+ }
55+ if member .Member .Phase != api .MemberPhaseCreated {
56+ // Only make changes when phase is created
57+ continue
58+ }
59+ if member .Member .PersistentVolumeClaimName == "" {
60+ // Plan is irrelevant without PVC
61+ continue
62+ }
63+ groupSpec := spec .GetServerGroupSpec (member .Group )
5564
56- if ! plan .IsEmpty () && groupSpec .VolumeResizeMode .Get () == api .PVCResizeModeRotate {
57- // Only 1 change at a time
58- return nil
59- }
65+ if groupSpec .VolumeResizeMode .Get () != mode {
66+ continue
67+ }
6068
61- // Load PVC
62- pvc , exists := cache .PersistentVolumeClaim ().V1 ().GetSimple (m .PersistentVolumeClaimName )
63- if ! exists {
64- r .planLogger .
65- Str ("role" , group .AsRole ()).
66- Str ("id" , m .ID ).
67- Warn ("Failed to get PVC" )
68- continue
69- }
69+ if ! plan .IsEmpty () && groupSpec .VolumeResizeMode .Get () == api .PVCResizeModeRotate {
70+ // Only 1 change at a time
71+ continue
72+ }
7073
71- var res core.ResourceList
72- if groupSpec .HasVolumeClaimTemplate () {
73- res = groupSpec .GetVolumeClaimTemplate ().Spec .Resources .Requests
74- } else {
75- res = groupSpec .Resources .Requests
76- }
77- if requestedSize , ok := res [core .ResourceStorage ]; ok {
78- if volumeSize , ok := pvc .Spec .Resources .Requests [core .ResourceStorage ]; ok {
79- cmp := volumeSize .Cmp (requestedSize )
80- if cmp < 0 {
81- plan = append (plan , r .pvcResizePlan (group , groupSpec , m )... )
82- }
74+ // Load PVC
75+ pvc , exists := cache .PersistentVolumeClaim ().V1 ().GetSimple (member .Member .PersistentVolumeClaimName )
76+ if ! exists {
77+ r .planLogger .
78+ Str ("role" , member .Group .AsRole ()).
79+ Str ("id" , member .Member .ID ).
80+ Warn ("Failed to get PVC" )
81+ continue
82+ }
83+
84+ var res core.ResourceList
85+ if groupSpec .HasVolumeClaimTemplate () {
86+ res = groupSpec .GetVolumeClaimTemplate ().Spec .Resources .Requests
87+ } else {
88+ res = groupSpec .Resources .Requests
89+ }
90+ if requestedSize , ok := res [core .ResourceStorage ]; ok {
91+ if volumeSize , ok := pvc .Spec .Resources .Requests [core .ResourceStorage ]; ok {
92+ cmp := volumeSize .Cmp (requestedSize )
93+ if cmp < 0 {
94+ // Here we need to do proper calculation
95+ plan = append (plan , r .pvcResizePlan (member .Group , member .Member , mode )... )
8396 }
8497 }
8598 }
86- return nil
87- })
99+ }
88100
89101 return plan
90102}
@@ -118,8 +130,7 @@ func (r *Reconciler) createRotateServerStoragePVCPendingResizeConditionPlan(ctx
118130 return plan
119131}
120132
121- func (r * Reconciler ) pvcResizePlan (group api.ServerGroup , groupSpec api.ServerGroupSpec , member api.MemberStatus ) api.Plan {
122- mode := groupSpec .VolumeResizeMode .Get ()
133+ func (r * Reconciler ) pvcResizePlan (group api.ServerGroup , member api.MemberStatus , mode api.PVCResizeMode ) api.Plan {
123134 switch mode {
124135 case api .PVCResizeModeRuntime :
125136 return api.Plan {
0 commit comments