Skip to content

Conversation

@michaelhtm
Copy link
Member

@michaelhtm michaelhtm commented Apr 4, 2025

Issue #2406

Description of changes:
The changes handle the addition of a new adoption-policy called adopt-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-fields annotation. Requiring the Spec fields be in Spec
for 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:

Controller looks for resource in AWS
If found
   check if there are any differences between user resource definition (desired) and 
    resource definition in AWS (latest). Update if there are any differences
If not Found
  create the resource

Unlike the adopt adoption policy, if a resource has adopt-or-create policy and read-only, and it is not found
in 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.

@ack-prow ack-prow bot requested review from a-hilaly and jlbutler April 4, 2025 22:58
@ack-prow
Copy link

ack-prow bot commented Apr 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: michaelhtm
Once this PR has been reviewed and has the lgtm label, please assign a-hilaly for approval by writing /assign @a-hilaly in a comment. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@michaelhtm michaelhtm changed the title feat: Adopt-or-Create feature feat: Adopt-or-Create Apr 4, 2025
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
@michaelhtm michaelhtm force-pushed the feat/adoptorcreate branch from efde0ab to 2163f84 Compare April 5, 2025 01:14
@gfaraj
Copy link

gfaraj commented Apr 7, 2025

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?

@michaelhtm
Copy link
Member Author

@gfaraj Hello, The entire manifest would be replaced with the spec defined in AWS if the adoption-policy is adopt. With the current implementation, if it's adopt-or-create, the controller will do an update after the adoption, if not it will create the resource. Maybe we need a better name than adopt-or-create..

@gfaraj
Copy link

gfaraj commented Apr 7, 2025

@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?

@michaelhtm michaelhtm force-pushed the feat/adoptorcreate branch from 2310560 to 8bf6a25 Compare April 8, 2025 22:07
@michaelhtm
Copy link
Member Author

/test sagemaker-controller-test

Copy link
Member

@a-hilaly a-hilaly left a 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)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

not really. privatizing...

Copy link
Member Author

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..

Comment on lines 324 to 327
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...
Copy link
Member

Choose a reason for hiding this comment

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

yes 💯

Copy link
Member

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.

Copy link
Member Author

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...

Copy link
Member Author

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)

return latest, err
}
if isAdopted {
if adoptionPolicy == AdoptPolicy || isAdopted {
Copy link
Member

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

Copy link
Member Author

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

return latest, err
}
} else {
} else if adoptionPolicy == AdoptPolicy {
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

➕1

Copy link
Member

@rushmash91 rushmash91 left a 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?
Copy link
Member

@rushmash91 rushmash91 Apr 22, 2025

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

Copy link
Member Author

@michaelhtm michaelhtm Apr 22, 2025

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..

@michaelhtm
Copy link
Member Author

/test sagemaker-controller-test

@ack-prow
Copy link

ack-prow bot commented Apr 25, 2025

@michaelhtm: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
verify-attribution 6f7e297 link false /test verify-attribution
sagemaker-controller-test 6f7e297 link true /test sagemaker-controller-test

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.

@rushmash91 rushmash91 merged commit 910ed2a into aws-controllers-k8s:main Apr 25, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants