Skip to content

Commit

Permalink
Merge pull request #751 from pohly/automated-cherry-pick-of-#696-orig…
Browse files Browse the repository at this point in the history
…in-release-3.1

Automated cherry pick of #696: fix maximumVolumeSize not updated
  • Loading branch information
k8s-ci-robot committed Jun 14, 2022
2 parents e1f566e + a10b9b5 commit b4b5033
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/capacity/capacity.go
Expand Up @@ -642,8 +642,9 @@ func (c *Controller) syncCapacity(ctx context.Context, item workItem) error {
// scenario that we end up creating two objects for the same work item, the second
// one will be recognized as duplicate and get deleted again once we receive it.
} else if capacity.Capacity.Value() == quantity.Value() &&
sizesAreEqual(capacity.MaximumVolumeSize, maximumVolumeSize) &&
(c.owner == nil || c.isOwnedByUs(capacity)) {
klog.V(5).Infof("Capacity Controller: no need to update %s for %+v, same capacity %v and correct owner", capacity.Name, item, quantity)
klog.V(5).Infof("Capacity Controller: no need to update %s for %+v, same capacity %v, same maximumVolumeSize %v and correct owner", capacity.Name, item, quantity, maximumVolumeSize)
return nil
} else {
// Update existing object. Must not modify object in the informer cache.
Expand All @@ -654,7 +655,7 @@ func (c *Controller) syncCapacity(ctx context.Context, item workItem) error {
capacity.OwnerReferences = append(capacity.OwnerReferences, *c.owner)
}
var err error
klog.V(5).Infof("Capacity Controller: updating %s for %+v, new capacity %v", capacity.Name, item, quantity)
klog.V(5).Infof("Capacity Controller: updating %s for %+v, new capacity %v, new maximumVolumeSize %v", capacity.Name, item, quantity, maximumVolumeSize)
capacity, err = c.client.StorageV1beta1().CSIStorageCapacities(capacity.Namespace).Update(ctx, capacity, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("update CSIStorageCapacity for %+v: %v", item, err)
Expand Down Expand Up @@ -831,3 +832,16 @@ func (c *Controller) isManaged(capacity *storagev1beta1.CSIStorageCapacity) bool
return capacity.Labels[DriverNameLabel] == c.driverName &&
capacity.Labels[ManagedByLabel] == c.managedByID
}

func sizesAreEqual(expected, actual *resource.Quantity) bool {
if expected == actual {
// Both nil or pointer to same value.
return true
}
if expected == nil || actual == nil {
// can not compare nil with non-nil.
return false
}
// Both not nil, compare values.
return expected.Value() == actual.Value()
}

0 comments on commit b4b5033

Please sign in to comment.