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 ackcompare.GetTagsDifference helper method #109

Merged

Conversation

RedbackThomson
Copy link
Contributor

@RedbackThomson RedbackThomson commented Feb 3, 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:

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.

@ack-prow ack-prow bot requested review from jljaco and vijtrip2 February 3, 2023 03:34
@ack-prow ack-prow bot added the approved label Feb 3, 2023
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.

Great stuff, @RedbackThomson :)

@@ -44,9 +44,11 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/samber/lo v1.37.0 // indirect
Copy link
Collaborator

Choose a reason for hiding this comment

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

\o/

Comment on lines +27 to +36
// we need to convert the tag tuples to a comparable interface type
fromPairs := lo.ToPairs(from)
toPairs := lo.ToPairs(to)

left, right := lo.Difference(fromPairs, toPairs)
middle := lo.Intersect(fromPairs, toPairs)

removed = lo.FromPairs(left)
added = lo.FromPairs(right)
unchanged = lo.FromPairs(middle)
Copy link
Collaborator

Choose a reason for hiding this comment

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

cool use of samber/lo utilities. ++

Copy link

@jljaco jljaco left a comment

Choose a reason for hiding this comment

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

/lgtm

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

ack-prow bot commented Feb 5, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jaypipes, jljaco, 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,jljaco]

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 7152103 into aws-controllers-k8s:main Feb 5, 2023
@RedbackThomson RedbackThomson deleted the common-tag-compare branch February 7, 2023 17:59
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.

3 participants