Skip to content

Commit b24df22

Browse files
[Feature] Move PVC resize action to high-priority plan (#1051)
1 parent 2eacf10 commit b24df22

File tree

4 files changed

+61
-48
lines changed

4 files changed

+61
-48
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Bugfix) Ensure pod names not too long
55
- (Refactor) Use cached member's clients
6+
- (Feature) Move PVC resize action to high-priority plan
67

78
## [1.2.14](https://github.com/arangodb/kube-arangodb/tree/1.2.14) (2022-07-14)
89
- (Feature) Add ArangoSync TLS based rotation

pkg/deployment/reconcile/plan_builder_high.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
// createHighPlan considers the given specification & status and creates a plan to get the status in line with the specification.
3636
// If a plan already exists, the given plan is returned with false.
37-
// Otherwise the new plan is returned with a boolean true.
37+
// Otherwise, the new plan is returned with a boolean true.
3838
func (r *Reconciler) createHighPlan(ctx context.Context, apiObject k8sutil.APIObject,
3939
currentPlan api.Plan, spec api.DeploymentSpec,
4040
status api.DeploymentStatus,
@@ -52,6 +52,7 @@ func (r *Reconciler) createHighPlan(ctx context.Context, apiObject k8sutil.APIOb
5252
ApplyIfEmpty(r.updateMemberRotationConditionsPlan).
5353
ApplyIfEmpty(r.createMemberRecreationConditionsPlan).
5454
ApplyIfEmpty(r.createRotateServerStoragePVCPendingResizeConditionPlan).
55+
ApplyIfEmpty(r.createRotateServerStorageResizePlanRuntime).
5556
ApplyIfEmpty(r.createTopologyMemberUpdatePlan).
5657
ApplyIfEmptyWithBackOff(LicenseCheck, 30*time.Second, r.updateClusterLicense).
5758
ApplyIfEmpty(r.createTopologyMemberConditionPlan).

pkg/deployment/reconcile/plan_builder_normal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (r *Reconciler) createNormalPlan(ctx context.Context, apiObject k8sutil.API
7272
ApplySubPlanIfEmpty(r.createTLSStatusPropagatedFieldUpdate, r.createCARenewalPlan).
7373
ApplySubPlanIfEmpty(r.createTLSStatusPropagatedFieldUpdate, r.createCAAppendPlan).
7474
ApplyIfEmpty(r.createKeyfileRenewalPlan).
75-
ApplyIfEmpty(r.createRotateServerStorageResizePlan).
75+
ApplyIfEmpty(r.createRotateServerStorageResizePlanRotate).
7676
ApplySubPlanIfEmpty(r.createTLSStatusPropagatedFieldUpdate, r.createRotateTLSServerSNIPlan).
7777
ApplyIfEmpty(r.createRestorePlan).
7878
ApplySubPlanIfEmpty(r.createEncryptionKeyStatusPropagatedFieldUpdate, r.createEncryptionKeyCleanPlan).

pkg/deployment/reconcile/plan_builder_storage.go

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)