Skip to content

Commit

Permalink
Retry status updates in case resource changes during reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
ewrenn8 committed Aug 12, 2021
1 parent adae427 commit 986f184
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pkg/packageinstall/packageinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,28 @@ func (pi *PackageInstallCR) update(updateFunc func(*pkgingv1alpha1.PackageInstal
pi.log.Info("Updating installed package")

modelForUpdate := pi.model.DeepCopy()
updateFunc(modelForUpdate)

var err error
var lastErr error
for i := 0; i < 5; i++ {
updateFunc(modelForUpdate)

pi.model, err = pi.kcclient.PackagingV1alpha1().PackageInstalls(modelForUpdate.Namespace).Update(
context.Background(), modelForUpdate, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("Updating installed package: %s", err)
}
updatedModel, err := pi.kcclient.PackagingV1alpha1().PackageInstalls(modelForUpdate.Namespace).Update(
context.Background(), modelForUpdate, metav1.UpdateOptions{})
if err == nil {
pi.model = updatedModel
pi.unmodifiedModel = updatedModel.DeepCopy()
return nil
}

pi.unmodifiedModel = pi.model.DeepCopy()
lastErr = err

return nil
// if we errored, refresh the model we have
modelForUpdate, err = pi.kcclient.PackagingV1alpha1().PackageInstalls(modelForUpdate.Namespace).Get(
context.Background(), modelForUpdate.Name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Getting package install model: %s", err)
}
}

return fmt.Errorf("Updating package install: %s", lastErr)
}

0 comments on commit 986f184

Please sign in to comment.