Skip to content

Commit

Permalink
Merge pull request #335 from vmware-tanzu/fix-pkgi-race
Browse files Browse the repository at this point in the history
Retry status updates in case resource changes during reconciliation
  • Loading branch information
ewrenn8 authored Aug 12, 2021
2 parents b1b224e + 986f184 commit 34e7f46
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 34e7f46

Please sign in to comment.