Storage: GuaranteedUpdate fix & other improvements (#85206)

make GuaranteedUpdate work when ignoring not found errors, increase poll frequency, fix Delete
This commit is contained in:
Dan Cech
2024-03-27 10:38:49 -04:00
committed by GitHub
parent 2ecc1bb646
commit ef26fe95dc
3 changed files with 47 additions and 10 deletions

View File

@@ -511,9 +511,14 @@ func (s *Storage) GuaranteedUpdate(
Subresource: requestInfo.Subresource,
}
err := s.Get(ctx, k.String(), storage.GetOptions{}, destination)
if err != nil {
return err
getErr := s.Get(ctx, k.String(), storage.GetOptions{}, destination)
if getErr != nil {
if ignoreNotFound && apierrors.IsNotFound(getErr) {
// destination is already set to zero value
// we'll create the resource
} else {
return getErr
}
}
accessor, err := meta.Accessor(destination)
@@ -544,6 +549,27 @@ func (s *Storage) GuaranteedUpdate(
return err
}
// if we have a non-nil getErr, then we've ignored a not found error
if getErr != nil {
// object does not exist, create it
req := &entityStore.CreateEntityRequest{
Entity: e,
}
rsp, err := s.store.Create(ctx, req)
if err != nil {
return err
}
err = entityToResource(rsp.Entity, destination, s.codec)
if err != nil {
return apierrors.NewInternalError(err)
}
return nil
}
// update the existing object
req := &entityStore.UpdateEntityRequest{
Entity: e,
PreviousVersion: previousVersion,