Skip to content

Adding upsert for adopt-or-create #184

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JonathanGraniero
Copy link

@JonathanGraniero JonathanGraniero commented May 13, 2025

Issue: aws-controllers-k8s/community#2481

Description of changes:

When using the adopt-or-create annotation, the current functionality is that it will come up with reconcile errors if you are trying to adopting an existing resource on second reconcile. What is happening is that when there are differences in the spec compared to what is deployed, it's error'ing out and failing due to a mismatch on resources.

In most cases, the resource values in ACK should be the accepted source of truth and this should be an upsert.

The goal of this PR is that the desired manifest should be set as the latest manifest, so that when the controller reconciles the changes, it overrides the deployed values with the values in the spec section from the resource manifest.

For example, I have a queue named my-queue that is currently deployed. All of the resources are the same as below. The exception would be visibilityTimeout which is set at 300.

apiVersion: sqs.services.k8s.aws/v1alpha1
kind: Queue
metadata:
  annotations:
    argocd.argoproj.io/sync-wave: '-1'
  services.k8s.aws/adoption-policy: adopt-or-create
  finalizers:
    - finalizers.sqs.services.k8s.aws/Queue
  generation: 2
  labels:
    app: my-app
    app.kubernetes.io/instance: my-app
    queue-type: primary
  name: my-queue
  namespace: namespace
spec:
  delaySeconds: '0'
  maximumMessageSize: '262144'
  messageRetentionPeriod: '1209600'
  queueName: my-queue
  receiveMessageWaitTimeSeconds: '0'
  visibilityTimeout: 30

I would expect the visibility timeout to be updated on my deployed queue to be 30 rather than the 300 that is currently deployed. The current behavior is that this would fail to reconcile due to a mismatch on the field.

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 added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 13, 2025
Copy link

ack-prow bot commented May 13, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JonathanGraniero
Once this PR has been reviewed and has the lgtm label, please assign michaelhtm for approval by writing /assign @michaelhtm 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

@ack-prow ack-prow bot requested review from jlbutler and knottnt May 13, 2025 19:16
Copy link

ack-prow bot commented May 13, 2025

Hi @JonathanGraniero. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 13, 2025
@JonathanGraniero
Copy link
Author

I'm going to open this when it's ready to review, I'm still working on the test but just opened this in draft to visibly see my changes before making filling out the details.

@JonathanGraniero JonathanGraniero marked this pull request as ready for review May 13, 2025 21:10
@ack-prow ack-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 13, 2025
@ack-prow ack-prow bot requested review from a-hilaly and michaelhtm May 13, 2025 21:10
@JonathanGraniero JonathanGraniero changed the title adding upsert for adopt-or-create Adding upsert for adopt-or-create May 13, 2025
Copy link
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

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

Hello @JonathanGraniero
Thank you for the contribution!
Left one inline comment!

Comment on lines +341 to +351
if adoptionPolicy == AdoptionPolicy_AdoptOrCreate {
err = populated.PopulateResourceFromAnnotation(adoptionFields)
if err != nil {
rlog.Debug("Ignoring adoption field population error for adopt-or-create", "error", err)
}
} else {
// For regular adoption, maintain existing behavior
err = populated.PopulateResourceFromAnnotation(adoptionFields)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

For this one, we were planning on implementing a different method.
Instead of PopulateResourceFromAnnotation we can give the method context of whether it is adopt or adopt-or-create. This will allow it to either Populate both Spec and Status, or only Status.

Honestly i'm not sure what the expected Error should be if you need to provide a required field in Status on adopt-or-create but you fail to do so. Should that be a terminal error? Or just return nothing, and just create the resource...
cc: @gfaraj @havard024

Copy link
Author

Choose a reason for hiding this comment

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

I'm open to suggestions here, what I was trying to solve for here is that in the process of doing my migration, I found that I had some resources that were setup incorrectly and were not standardized. So I want to standardize them in one shot rather than doing first getting the reconciler to accept the adopted policy, then go and remove the extra code that I was just doing to be able to adopt the resource.

If this is in line with what y'all need to, or you need me to add some more branching logic, totally up to adding that in here.

Copy link
Member

Choose a reason for hiding this comment

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

Can you test your use case with the latest released controllers? I believe this issue came up before, and we just cut releases for it today..

Copy link
Member

Choose a reason for hiding this comment

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

can you also create an issue describing the issue you encountered? just in case we also have it in other controllers

Copy link
Author

Choose a reason for hiding this comment

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

Done! aws-controllers-k8s/community#2481 I'll also update that in the PR description

Copy link
Member

Choose a reason for hiding this comment

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

Thank you @JonathanGraniero
just responded on the Github issue. I believe this was resolved in the latest release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants