Skip to content

Commit

Permalink
Merge pull request #1573 from ondrej-smola/externally-resized-pvc
Browse files Browse the repository at this point in the history
Inherit PVC storage value if current value is greater than value in spec
  • Loading branch information
sunsingerus authored Nov 29, 2024
2 parents 58b484e + 5a0a40e commit 7d67c0c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/controller/common/storage/storage-pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *PVC) UpdateOrCreate(ctx context.Context, pvc *core.PersistentVolumeClai
return nil, fmt.Errorf("task is done")
}

_, err := c.Get(ctx, pvc.Namespace, pvc.Name)
oldPvc, err := c.Get(ctx, pvc.Namespace, pvc.Name)
if err != nil {
if apiErrors.IsNotFound(err) {
log.V(1).M(pvc).F().Error("PVC not found, need to create %s", util.NamespacedName(pvc))
Expand All @@ -62,6 +62,14 @@ func (c *PVC) UpdateOrCreate(ctx context.Context, pvc *core.PersistentVolumeClai
// In case of any non-NotFound API error - unable to proceed
log.V(1).M(pvc).F().Error("ERROR unable to get PVC(%s) err: %v", util.NamespacedName(pvc), err)
return nil, err
}

oldStorageRequest := oldPvc.Spec.Resources.Requests[core.ResourceStorage]
newStorageRequest := pvc.Spec.Resources.Requests[core.ResourceStorage]

if oldStorageRequest.Cmp(newStorageRequest) == 1 {
log.V(1).M(pvc).F().Info("PVC storage was increased externally to greater value and value cannot be decreased, using greater value")
pvc.Spec.Resources.Requests[core.ResourceStorage] = oldStorageRequest
}

pvcUpdated, err := c.Update(ctx, pvc)
Expand Down

0 comments on commit 7d67c0c

Please sign in to comment.