-
Notifications
You must be signed in to change notification settings - Fork 180
feat: Adopt-or-Create #179
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
feat: Adopt-or-Create #179
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: michaelhtm The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Allow users to create the resource if adoption fails due to a `NotFound` error. With these changes, we are expecting users to populate all the necessary fields for creation in the reosurce spec, and the status fileds in the `adoption-fields` annotation
efde0ab to
2163f84
Compare
|
Hi @michaelhtm! Quick question -- will this overwrite the entire Kubernetes manifest if it's able to adopt an existing resource? From the code I'm seeing, it seems like that's the case. In my case, I would like to avoid that if possible. Overwriting the manifest from the adopted resource means I have to hit "sync" again for my argo app. Really, I just want to upsert my resource to match my ACK spec. While I think overwriting the whole thing does seem like a valid use case, maybe it's possible to support both cases? Might be looking at a separate adoption policy of "upsert" or something like that? |
|
@gfaraj Hello, The entire manifest would be replaced with the spec defined in AWS if the |
|
@michaelhtm oh nice, thanks for confirming that, I may have misread part of the changes. Yeah then this seems more like an "upsert" -- maybe that should be the policy name instead? |
2310560 to
8bf6a25
Compare
6bb2bdd to
e9c2402
Compare
|
/test sagemaker-controller-test |
7a922a2 to
0a84239
Compare
a-hilaly
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.
Thanks @michaelhtm ! Looks good overall, I left a few comments below
|
|
||
| rlog.Info("Adopting Resource") | ||
| extractedFields, err := ExtractAdoptionFields(desired) | ||
| adoptionFields, err := ExtractAdoptionFields(desired) |
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.
does ExtractAdoptionFields need to be public?
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.
not really. privatizing...
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.
Actually there's more functions in util.go that are public without needing to be..we can change their signature during the next refactor..
| err = populated.PopulateResourceFromAnnotation(adoptionFields) | ||
| // maybe don't return errors when it's adopt-or-create? | ||
| // TODO (michaelhtm) change PopulateResourceFromAnnotation to understand | ||
| // adopt-or-create, and validate Spec fields are not nil... |
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 💯
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.
or maybe PopulateResourceFromAnnotation shouldn't return an error? how about a boolean, stating whether a resource got populated or not.
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.
For this, i was mostly thinking we can pass the adoptionPolicy to PopulateResourceFromAnnotation. Doing so, we can decide not to populate Spec fields if the policy is Adopt-Or-Create...
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.
Or..we can divide this up into two..PopulateSpecFromAnnotations, and PopulateStatusFromAnnotation..(we need a better name)
pkg/runtime/reconciler.go
Outdated
| return latest, err | ||
| } | ||
| if isAdopted { | ||
| if adoptionPolicy == AdoptPolicy || isAdopted { |
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.
do you also want to check for needAdoption
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.
i check that early on..adoptionPolicy = "" if !needAdoption
pkg/runtime/reconciler.go
Outdated
| return latest, err | ||
| } | ||
| } else { | ||
| } else if adoptionPolicy == AdoptPolicy { |
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.
ditto
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: maybe it's about time to factor the Sync function in multiple small functions? maybe in a seperate PR? looks like it's growing exponentially, and most of it's logic is really the core of ACK.
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.
➕1
rushmash91
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.
Nice @michaelhtm !! would be great to have more details in the PR description.
| resolved, hasReferences, err := rm.ResolveReferences(ctx, r.apiReader, desired) | ||
| rlog.Exit("rm.ResolveReferences", err) | ||
| if err != nil { | ||
| // TODO (michaelhtm): should we fail here for `adopt-or-create` adoption policy? |
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.
Failing is consistent here.. this is why we see the issues like the adoption fails in VPC Peering in ec2 (for just adopt)?
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.
The VPCPeering error was mostly happening after the adoption path was successful..
0016367 to
6f7e297
Compare
|
/test sagemaker-controller-test |
|
@michaelhtm: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Issue #2406
Description of changes:
The changes handle the addition of a new
adoption-policycalledadopt-or-create.The adopt-or-create policy requires users to define the Spec fields in the resource Spec,
and the Status fields in the
adoption-fieldsannotation. Requiring the Spec fields be in Specfor adopt-or-create ensures that the users provide fields that may also be required for a create
operation.
Here is the controller lifecycle of adopt-or-create policy:
Unlike the
adoptadoption policy, if a resource hasadopt-or-createpolicy andread-only, and it is not foundin AWS, the controller will mark that resource with a terminal error.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.