-
Notifications
You must be signed in to change notification settings - Fork 249
Create options secret before bd #4284
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
Create options secret before bd #4284
Conversation
f32934c to
faf4260
Compare
0xavi0
left a comment
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... just a question in case I missed something
| // reference from its creation or latest update. | ||
| if op == controllerutil.OperationResultCreated { | ||
| if err := r.ensureOwnerReferences(ctx, bd, optionsSecret); err != nil { | ||
| return r.computeResult(ctx, logger, bundleOrig, bundle, "failed to ensure owner references are set in options secret", err) |
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.
Question: What’s the advantage of setting the owner reference when calling manageOptionsSecret? That we skip this call in here when updating?
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.
Yes, that's the idea:
// If the bundle deployment already existed and has simply been updated, the secret will already bear an owner
// reference from its creation or latest update.
If the bundle has been updated, its owner reference should already be set by manageOptionsSecret, which created or updated the secret. This is an optimisation.
On the other hand, if the bundle was created, it did then not yet exist when manageOptionsSecret was called, hence the need to ensure the owner reference is set here.
Getting a bundle and returning a bundle with a finalizer now lives in a separate function to make test cases more concise, as that logic is called a few times.
This should clarify, from one place, where content creation and update calls are made from and why.
Both cases are now covered, with comments for better readability.
A couple of comments clarify why those expectations exist, which should make tests easier to maintain.
Based on an idea from rancher#3889 by Alejandro Ruiz, the bundle controller now creates an options secret, if such a secret is needed, before the bundle deployment which will end up owning it. This should prevent some errors about missing secrets.
Setting an owner reference pointing to a bundle deployment on its options secret can be done when creating or updating the secret, if the bundle deployment already exists. This works even if the bundle deployment is outdated, to be subsequently updated, because its UID is immutable. This could save the bundle controller a few separate secret update requests when repeatedly updating multiple bundle deployments.
faf4260 to
484774e
Compare
In order to prevent errors triggered by a missing or outdated options secret, the bundle controller now creates/updates it before creating/updating the bundle deployment owning it.
Updating bundle controller unit tests to fit with this new logic was easier after a bit of simplification, hence the additional diff.
Supersedes #3889.
Additional Information
Checklist
- [ ] I have updated the documentation via a pull request in thefleet-docs repository.