mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Bugfix] Fix Volume Resize on Single Mode (#802)
This commit is contained in:
parent
0461391d1a
commit
b60b48eb28
3 changed files with 60 additions and 14 deletions
|
@ -4,6 +4,7 @@
|
||||||
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation
|
- Replace `beta.kubernetes.io/arch` Pod label with `kubernetes.io/arch` using Silent Rotation
|
||||||
- Add "Short Names" feature
|
- Add "Short Names" feature
|
||||||
- Switch ArangoDB Image Discovery process from Headless Service to Pod IP
|
- Switch ArangoDB Image Discovery process from Headless Service to Pod IP
|
||||||
|
- Fix PVC Resize for Single servers
|
||||||
|
|
||||||
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
|
## [1.2.3](https://github.com/arangodb/kube-arangodb/tree/1.2.3) (2021-09-24)
|
||||||
- Update UBI Image to 8.4
|
- Update UBI Image to 8.4
|
||||||
|
|
|
@ -104,6 +104,7 @@ func createNormalPlan(ctx context.Context, log zerolog.Logger, apiObject k8sutil
|
||||||
ApplySubPlanIfEmpty(createTLSStatusPropagatedFieldUpdate, createCAAppendPlan).
|
ApplySubPlanIfEmpty(createTLSStatusPropagatedFieldUpdate, createCAAppendPlan).
|
||||||
ApplyIfEmpty(createKeyfileRenewalPlan).
|
ApplyIfEmpty(createKeyfileRenewalPlan).
|
||||||
ApplyIfEmpty(createRotateServerStoragePlan).
|
ApplyIfEmpty(createRotateServerStoragePlan).
|
||||||
|
ApplyIfEmpty(createRotateServerStorageResizePlan).
|
||||||
ApplySubPlanIfEmpty(createTLSStatusPropagatedFieldUpdate, createRotateTLSServerSNIPlan).
|
ApplySubPlanIfEmpty(createTLSStatusPropagatedFieldUpdate, createRotateTLSServerSNIPlan).
|
||||||
ApplyIfEmpty(createRestorePlan).
|
ApplyIfEmpty(createRestorePlan).
|
||||||
ApplySubPlanIfEmpty(createEncryptionKeyStatusPropagatedFieldUpdate, createEncryptionKeyCleanPlan).
|
ApplySubPlanIfEmpty(createEncryptionKeyStatusPropagatedFieldUpdate, createEncryptionKeyCleanPlan).
|
||||||
|
|
|
@ -45,10 +45,9 @@ func createRotateServerStoragePlan(ctx context.Context,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var plan api.Plan
|
var plan api.Plan
|
||||||
var canContinue = true
|
|
||||||
status.Members.ForeachServerGroup(func(group api.ServerGroup, members api.MemberStatusList) error {
|
status.Members.ForeachServerGroup(func(group api.ServerGroup, members api.MemberStatusList) error {
|
||||||
for _, m := range members {
|
for _, m := range members {
|
||||||
if !plan.IsEmpty() && !canContinue {
|
if !plan.IsEmpty() {
|
||||||
// Only 1 change at a time
|
// Only 1 change at a time
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -74,9 +73,6 @@ func createRotateServerStoragePlan(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.StringOrDefault(pvc.Spec.StorageClassName) != storageClassName && storageClassName != "" {
|
if util.StringOrDefault(pvc.Spec.StorageClassName) != storageClassName && storageClassName != "" {
|
||||||
// Do not append more than 1 operation if we replace storageClass
|
|
||||||
canContinue = false
|
|
||||||
|
|
||||||
// Storageclass has changed
|
// Storageclass has changed
|
||||||
log.Info().Str("pod-name", m.PodName).
|
log.Info().Str("pod-name", m.PodName).
|
||||||
Str("pvc-storage-class", util.StringOrDefault(pvc.Spec.StorageClassName)).
|
Str("pvc-storage-class", util.StringOrDefault(pvc.Spec.StorageClassName)).
|
||||||
|
@ -106,15 +102,8 @@ func createRotateServerStoragePlan(ctx context.Context,
|
||||||
if requestedSize, ok := res[core.ResourceStorage]; ok {
|
if requestedSize, ok := res[core.ResourceStorage]; ok {
|
||||||
if volumeSize, ok := pvc.Spec.Resources.Requests[core.ResourceStorage]; ok {
|
if volumeSize, ok := pvc.Spec.Resources.Requests[core.ResourceStorage]; ok {
|
||||||
cmp := volumeSize.Cmp(requestedSize)
|
cmp := volumeSize.Cmp(requestedSize)
|
||||||
if cmp < 0 {
|
// Only schrink is possible
|
||||||
if groupSpec.VolumeResizeMode.Get() == api.PVCResizeModeRotate {
|
if cmp > 0 {
|
||||||
// Do not append more than 1 operation if we hard restart member
|
|
||||||
canContinue = false
|
|
||||||
}
|
|
||||||
plan = append(plan, pvcResizePlan(log, group, groupSpec, m.ID)...)
|
|
||||||
} else if cmp > 0 {
|
|
||||||
// Do not append more than 1 operation if we schrink volume
|
|
||||||
canContinue = false
|
|
||||||
|
|
||||||
if groupSpec.GetVolumeAllowShrink() && group == api.ServerGroupDBServers && !m.Conditions.IsTrue(api.ConditionTypeMarkedToRemove) {
|
if groupSpec.GetVolumeAllowShrink() && group == api.ServerGroupDBServers && !m.Conditions.IsTrue(api.ConditionTypeMarkedToRemove) {
|
||||||
plan = append(plan, api.NewAction(api.ActionTypeMarkToRemoveMember, group, m.ID))
|
plan = append(plan, api.NewAction(api.ActionTypeMarkToRemoveMember, group, m.ID))
|
||||||
|
@ -133,6 +122,61 @@ func createRotateServerStoragePlan(ctx context.Context,
|
||||||
return plan
|
return plan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createRotateServerStorageResizePlan creates plan to resize storage
|
||||||
|
func createRotateServerStorageResizePlan(ctx context.Context,
|
||||||
|
log zerolog.Logger, apiObject k8sutil.APIObject,
|
||||||
|
spec api.DeploymentSpec, status api.DeploymentStatus,
|
||||||
|
cachedStatus inspectorInterface.Inspector, context PlanBuilderContext) api.Plan {
|
||||||
|
var plan api.Plan
|
||||||
|
|
||||||
|
status.Members.ForeachServerGroup(func(group api.ServerGroup, members api.MemberStatusList) error {
|
||||||
|
for _, m := range members {
|
||||||
|
if m.Phase != api.MemberPhaseCreated {
|
||||||
|
// Only make changes when phase is created
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if m.PersistentVolumeClaimName == "" {
|
||||||
|
// Plan is irrelevant without PVC
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
groupSpec := spec.GetServerGroupSpec(group)
|
||||||
|
|
||||||
|
if !plan.IsEmpty() && groupSpec.VolumeResizeMode.Get() == api.PVCResizeModeRotate {
|
||||||
|
// Only 1 change at a time
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load PVC
|
||||||
|
pvc, exists := cachedStatus.PersistentVolumeClaim(m.PersistentVolumeClaimName)
|
||||||
|
if !exists {
|
||||||
|
log.Warn().
|
||||||
|
Str("role", group.AsRole()).
|
||||||
|
Str("id", m.ID).
|
||||||
|
Msg("Failed to get PVC")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var res core.ResourceList
|
||||||
|
if groupSpec.HasVolumeClaimTemplate() {
|
||||||
|
res = groupSpec.GetVolumeClaimTemplate().Spec.Resources.Requests
|
||||||
|
} else {
|
||||||
|
res = groupSpec.Resources.Requests
|
||||||
|
}
|
||||||
|
if requestedSize, ok := res[core.ResourceStorage]; ok {
|
||||||
|
if volumeSize, ok := pvc.Spec.Resources.Requests[core.ResourceStorage]; ok {
|
||||||
|
cmp := volumeSize.Cmp(requestedSize)
|
||||||
|
if cmp < 0 {
|
||||||
|
plan = append(plan, pvcResizePlan(log, group, groupSpec, m.ID)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return plan
|
||||||
|
}
|
||||||
|
|
||||||
func pvcResizePlan(log zerolog.Logger, group api.ServerGroup, groupSpec api.ServerGroupSpec, memberID string) api.Plan {
|
func pvcResizePlan(log zerolog.Logger, group api.ServerGroup, groupSpec api.ServerGroupSpec, memberID string) api.Plan {
|
||||||
mode := groupSpec.VolumeResizeMode.Get()
|
mode := groupSpec.VolumeResizeMode.Get()
|
||||||
switch mode {
|
switch mode {
|
||||||
|
|
Loading…
Reference in a new issue