Skip to content
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

add Delta.DifferentExcept() method #86

Merged
merged 1 commit into from
May 12, 2022

Conversation

jaypipes
Copy link
Collaborator

I need the ability to detect whether there are any differences in a
resource's fields other than a particular one. Basically, in doing the
tagging work for DBInstance, I came across a problem where we were
calling the ModifyDBInstance API call even though there were no changes
to DBInstance Spec fields other than the Tags collection.

So, I need to add the following in an sdk_update_pre_build_request
template for DBInstance:

if delta.DifferentAt("Spec.Tags") {
     if err = rm.SyncTags(ctx, desired, latest); err != nil {
         return nil, err
     }
}
if !delta.DifferentExcept("Spec.Tags") {
     // We don't want to proceed to call the ModifyDBInstance API since
     // no other resource fields have changed.
     return desired, nil
}

This PR adds the delta.DifferentExcept() implementation to enable the
above code.

Issue aws-controllers-k8s/community#1276

Signed-off-by: Jay Pipes jaypipes@gmail.com

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

I need the ability to detect whether there are any differences in a
resource's fields *other than* a particular one. Basically, in doing the
tagging work for DBInstance, I came across a problem where we were
calling the ModifyDBInstance API call even though there were no changes
to DBInstance Spec fields *other than* the Tags collection.

So, I need to add the following in an sdk_update_pre_build_request
template for DBInstance:

```go
if delta.DifferentAt("Spec.Tags") {
     if err = rm.SyncTags(ctx, desired, latest); err != nil {
         return nil, err
     }
}
if !delta.DifferentExcept("Spec.Tags") {
     // We don't want to proceed to call the ModifyDBInstance API since
     // no other resource fields have changed.
     return desired, nil
}
```

This PR adds the `delta.DifferentExcept()` implementation to enable the
above code.

Issue aws-controllers-k8s/community#1276

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
@RedbackThomson
Copy link
Contributor

Cute little helper method

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label May 12, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented May 12, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jaypipes, RedbackThomson

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [RedbackThomson,jaypipes]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 70b4f7c into aws-controllers-k8s:main May 12, 2022
@brucegucode
Copy link
Member

not too familiar with this code but code logic looks good to me
/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
No open projects
Status: Done
4 participants