Skip to content

Commit

Permalink
feat: forbid to shrink volume at cluster controller
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf committed Oct 11, 2023
1 parent cfde8f2 commit 5993713
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 5 deletions.
14 changes: 13 additions & 1 deletion controllers/apps/components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,20 +766,32 @@ func (c *rsmComponent) expandVolume(reqCtx intctrlutil.RequestCtx, cli client.Cl

func (c *rsmComponent) expandVolumes(reqCtx intctrlutil.RequestCtx, cli client.Client,
vctName string, proto *corev1.PersistentVolumeClaimTemplate) error {
pvcNotFound := false
for i := *c.runningWorkload.Spec.Replicas - 1; i >= 0; i-- {
pvc := &corev1.PersistentVolumeClaim{}
pvcKey := types.NamespacedName{
Namespace: c.GetNamespace(),
Name: fmt.Sprintf("%s-%s-%d", vctName, c.runningWorkload.Name, i),
}
pvcNotFound := false
if err := cli.Get(reqCtx.Ctx, pvcKey, pvc); err != nil {
if apierrors.IsNotFound(err) {
pvcNotFound = true
} else {
return err
}
}

if !pvcNotFound {
quantity := pvc.Spec.Resources.Requests.Storage()
newQuantity := proto.Spec.Resources.Requests.Storage()
if quantity.Cmp(*pvc.Status.Capacity.Storage()) == 0 && newQuantity.Cmp(*quantity) < 0 {
errMsg := fmt.Sprintf("shrinking the volume is not supported, volume: %s, quantity: %s, new quantity: %s",
pvc.GetName(), quantity.String(), newQuantity.String())
reqCtx.Event(c.Cluster, corev1.EventTypeWarning, "VolumeExpansionFailed", errMsg)
return fmt.Errorf("%s", errMsg)
}
}

if err := c.updatePVCSize(reqCtx, cli, pvcKey, pvc, pvcNotFound, proto); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 5993713

Please sign in to comment.