[unified-storage/apistore] Fix GuranteedUpdate skipping updates when `tryUpdate` is passed (#94557)

`GuranteedUpdate` method of `apistore.Storage` had a bug, where it would
errorneously conclude that the object is unchanged, in case a
`tryUpdate` function is passed that modifies the existing object itself
(as it is the case in many core types in K8s upstream).

The modified `existingObj` was compared with `updatedObj`, which would
essentially be same and this lead to the update being skipped.

This patch fixes this by always passing a copy of the `existingObj`.

Signed-off-by: Prem Kumar <prem.saraswat@grafana.com>
pull/94590/head
Prem Saraswat 9 months ago committed by GitHub
parent 95afb3a112
commit e2672021bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      pkg/storage/unified/apistore/store.go
  2. 12
      pkg/storage/unified/apistore/store_test.go

@ -465,7 +465,7 @@ func (s *Storage) GuaranteedUpdate(
return apierrors.NewNotFound(s.gr, req.Key.Name)
}
updatedObj, _, err = tryUpdate(existingObj, res)
updatedObj, _, err = tryUpdate(existingObj.DeepCopyObject(), res)
if err != nil {
if attempt >= MaxUpdateAttempts {
return err

@ -135,12 +135,12 @@ func TestDeleteWithSuggestion(t *testing.T) {
storagetesting.RunTestDeleteWithSuggestion(ctx, t, store)
}
//func TestDeleteWithSuggestionAndConflict(t *testing.T) {
// ctx, store, destroyFunc, err := testSetup(t)
// defer destroyFunc()
// assert.NoError(t, err)
// storagetesting.RunTestDeleteWithSuggestionAndConflict(ctx, t, store)
//}
func TestDeleteWithSuggestionAndConflict(t *testing.T) {
ctx, store, destroyFunc, err := testSetup(t)
defer destroyFunc()
assert.NoError(t, err)
storagetesting.RunTestDeleteWithSuggestionAndConflict(ctx, t, store)
}
// TODO: this test relies on update
//func TestDeleteWithSuggestionOfDeletedObject(t *testing.T) {

Loading…
Cancel
Save