Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry status updates in case resource changes during reconciliation #335

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for 5 retries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's just the number we went with last time we ran in to this

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)
}