Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #696: fix maximumVolumeSize not updated #751

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
}