Skip to content

Commit

Permalink
increment resourceVersion on successful updates
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Aug 19, 2024
1 parent 7cf5181 commit f2f584c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/registry/file/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (s *StorageImpl) writeFiles(key string, obj runtime.Object, metaOut runtime
if err := s.processor.PreSave(obj); err != nil {
return fmt.Errorf("processor.PreSave: %w", err)
}
// set resourceversion
// set resourceVersion
if version, _ := s.versioner.ObjectResourceVersion(obj); version == 0 {
if err := s.versioner.UpdateObject(obj, 1); err != nil {
return fmt.Errorf("set resourceVersion: %w", err)
Expand Down Expand Up @@ -521,6 +521,14 @@ func (s *StorageImpl) GuaranteedUpdate(
continue
}

// increment resourceVersion
if version, err := s.versioner.ObjectResourceVersion(ret); err == nil {
if err := s.versioner.UpdateObject(ret, version+1); err != nil {
logger.L().Ctx(ctx).Error("update object version failed", helpers.Error(err), helpers.String("key", key))
return err
}
}

// save to disk and fill into metaOut
err = s.writeFiles(key, ret, metaOut)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/file/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func TestStorageImpl_GuaranteedUpdate(t *testing.T) {
return nil, nil, fmt.Errorf("tryUpdate error")
}
obj := *input.(*v1beta1.SBOMSPDXv2p3)
obj.ResourceVersion = "3"
obj.ResourceVersion = "2"
obj.Spec.Metadata.Tool.Name = "tutu"
return &obj, nil, nil
},
Expand Down

0 comments on commit f2f584c

Please sign in to comment.