-
Notifications
You must be signed in to change notification settings - Fork 41
Add support for Policy Tag updates #15
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
Conversation
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.
Looks great! 🚀
nit: For the modify tags test, can you also add another new key and also delete an existing key? : )
The first patch deletes the |
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.
appreciate you picking up my slack, @RedbackThomson. thank you sir!
|
/test iam-kind-e2e |
|
@RedbackThomson looks like the test failure is legit: |
| sdk_update_post_set_output: | ||
| template_path: hooks/policy/sdk_update_post_set_output.go.tpl | ||
| update_operation: | ||
| custom_method_name: customUpdatePolicy |
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 just noticed something... I see you've added a custom_method_name configuration option to the generator.yaml file for the Policy resource (unlike the Role resource, which uses the sdk_update_post_set_output generic hook point.
I prefer to use the generic hook points instead of creating a custom update method. Can you change that?
LATER...
Never mind, @RedbackThomson, I realized now that you had to use a custom update method because there isn't an actual UpdatePolicy API call...
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.
Never mind, @RedbackThomson, I realized now that you had to use a custom update method because there isn't an actual UpdatePolicy API call...
Yeah this is a non-obvious configuration problem you have when trying to use hooks. I'll remove the hook point, though. Good call.
pkg/resource/policy/hooks.go
Outdated
| if len(toAdd) > 0 { | ||
| for _, t := range toAdd { | ||
| rlog.Debug("adding tag to policy", "key", *t.Key, "value", *t.Value) | ||
| } | ||
| if err = rm.addTags(ctx, r, toAdd); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if len(toDelete) > 0 { | ||
| for _, t := range toDelete { | ||
| rlog.Debug("removing tag from policy", "key", *t.Key, "value", *t.Value) | ||
| } | ||
| if err = rm.removeTags(ctx, r, toDelete); err != nil { | ||
| return 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.
@RedbackThomson so I'm wondering if the fact that we are doing the deletes AFTER the adds here is the cause of the test failure. When a Tag's value only is changed, the Tag will be in both the toAdd (the updated Tag k/v) and toDelete (the original Tag k/v) collections. I'm wondering if the the RemoveTags API call only looks at the Tag key? If that is the case, the call to RemoveTag will end up removing the Tag erroneously. An easy way of checking if my hypothesis is correct would be to simply change the order above and do the removeTags call before the addTags call.
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 think you're right, yeah. You should be able to use TagPolicy to update any tag, just by giving it an existing key with a new value. But for the sake of staying consistent with your hooks on Role, I'll just switch the order for now and make it do a delete then add.
I did test updating values in my manual testing and didn't see an issue, but I think combining an update with a delete might be the condition that is causing this problem here.
|
Tests failing due to:
I guess I'll wait a little while to retry? This throttling seems to take a while to lift. |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RedbackThomson, vijtrip2 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:
Approvers can indicate their approval by writing |
| if err := rm.syncTags(ctx, &resource{ko}); err != nil { | ||
| return nil, 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.
I believe this statement should go inside an if statement similar to:
if delta.DifferentAt("Spec.Tags") { ... }In the future we should also deal with cases when a user modifies other fields like: Description, PolicyDocument etc...
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.
Technically, there won't be any calls any update APIs if there aren't any changes (there will be an additional List operation, however, so we should be able to remove that call by guarding this with a delta.DifferentAt()` conditional. 👍
Fixes aws-controllers-k8s/community#1124
Description of changes:
Adds custom hook code to support the
TagPolicyandUntagPolicySDK methods for adding, updating and deleting tags on thePolicycustom resource.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.