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

Compare tags using common tag type #399

Merged

Conversation

RedbackThomson
Copy link
Contributor

Implements aws-controllers-k8s/community#1658

Description of changes:
Instead of comparing tag fields using the standard reflect.DeepEquals, this PR updates the code-generator to convert the tags to the common acktags.Tag type and then compare those as maps. This ensures that changes in ordering do not result in false positive deltas.

Controllers that rely on custom tag delta functions also typically use a function to determine which tags are being added and which are being removed. Using the same trick as this PR, a method can be added to the common runtime to deduce those - resulting in far less duplicated and verbose custom hook code. Those changes are not included in this PR, though.

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

@@ -333,12 +340,8 @@ func TestCompareResource_Lambda_Function(t *testing.T) {
delta.Add("Spec.Runtime", a.ko.Spec.Runtime, b.ko.Spec.Runtime)
}
}
if ackcompare.HasNilDifference(a.ko.Spec.Tags, b.ko.Spec.Tags) {
if !ackcompare.MapStringStringEqual(ToACKTags(a.ko.Spec.Tags), ToACKTags(b.ko.Spec.Tags)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In what package namespace is ToACKTags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, duh, yeah I forgot about that. I thought for a second it was in runtime's pkg/tags

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

👍 this is great, @RedbackThomson thank you!

ack-prow bot pushed a commit to aws-controllers-k8s/runtime that referenced this pull request Feb 5, 2023
Extends aws-controllers-k8s/code-generator#399

Description of changes:
Adds a `GetTagsDifference` helper method that can be used to determine which tags should be added and removed based on what they are going "from" and "to" - typically needed for services with `TagResource` and `UntagResource` operations. 

For example:
```go
aTags := ToACKTags(a.ko.Spec.Tags)
bTags := ToACKTags(b.ko.Spec.Tags)

added, _, removed := ackcompare.GetTagsDifference(aTags, bTags)

// optionally, convert back to service Tag type
toAdd := FromACKTags(added)
toRemove := FromACKTags(removed)
```

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
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.

To the moooooon 🌔

@a-hilaly
Copy link
Member

a-hilaly commented Feb 9, 2023

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 9, 2023
@ack-prow
Copy link

ack-prow bot commented Feb 9, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, 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 [A-Hilaly,RedbackThomson]

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 merged commit d13b586 into aws-controllers-k8s:main Feb 9, 2023
@@ -25,3 +25,6 @@ resources:
in:
- 1
- 2
CodeSigningConfig:
tags:
ignore: true
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own edification: why is this necessary here for Lambda.CodeSigningConfig but not for other applicable test cases like MemoryDB.User?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CodeSigningConfig doesn't support tags in its create call - https://docs.aws.amazon.com/sdk-for-go/api/service/lambda/#CreateCodeSigningConfigInput - and for the purposes of these tests we aren't adding the custom field to support it

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
None yet
Development

Successfully merging this pull request may close these issues.

4 participants