-
Notifications
You must be signed in to change notification settings - Fork 107
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
reconciler/managed: avoid temporary data loss to managed on annotation update #526
reconciler/managed: avoid temporary data loss to managed on annotation update #526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice optimization.
pkg/reconciler/managed/api.go
Outdated
@@ -172,12 +172,18 @@ func NewRetryingCriticalAnnotationUpdater(c client.Client) *RetryingCriticalAnno | |||
// reset to their current state according to the API server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps change this comment from "pending changes are reset" to "pending changes may be reset".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Do you think it's worth "E2E" testing this? It would have to be manual at the moment, unfortunately. (i.e. Build a provider using the updated reconciler.) |
That would be a tricky e2e. Certainly doable, but on the borderline of a test belonging into e2e. |
Actually, we should only retry with a Get on conflict. Let me change that before merging. On any other error we can just keep the old object and retry. |
f6a2f41
to
e2684ab
Compare
Have extended the unit tests and only get on conflict. |
pkg/reconciler/managed/api_test.go
Outdated
want error | ||
wantGetCalled bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Typically once we want more than one thing we nest them into a want
struct (similar to args
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
pkg/reconciler/managed/api_test.go
Outdated
getCalled := tc.args.o.GetAnnotations()["getcalled"] == "true" | ||
if getCalled != tc.wantGetCalled { | ||
t.Errorf("\n%s\nu.UpdateCriticalAnnotations(...) calling get: -want %v, +got %v", tc.reason, tc.wantGetCalled, getCalled) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// tc.want.o replaces tc.wantGetCalled
if diff := cmp.Diff(tc.want.o, tc.args.o,); diff != "" {
t.Errorf("\n%s\nu.UpdateCriticalAnnotations(...): -want, +got:\n%s", tc.reason, diff)
}
Nit: Typically in this case where we're testing for a mutation of the supplied object we'd use cmp.Diff
on the whole object as above. A little overkill here, but more extensible if we ever want to test more things about the object we're mutating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I like this pattern of adding an annotation to indicate that the fake client operated on the object. Could be worth generalizing and adopting elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
e2684ab
to
50c75a1
Compare
…n update Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
50c75a1
to
5b4ebc1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, thank you!
Description of your changes
When storing critical annotations, the retry loop always dropped changes to the
managed
resource object, i.e.part of the reconcile loop's effects on
managed
were just lost, always. This PR changes this to try one updateof the resource without reset (aka client get call), and only after that fall back into best-effort code path. In effect, this
might save a number of (expensive) reconciles.
I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested