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

feat: Add code generator for generic resource tagging #1378

Closed
wants to merge 2 commits into from

Conversation

MisterMX
Copy link
Collaborator

@MisterMX MisterMX commented Jul 4, 2022

Description of your changes

This adds a code generator that creates a method AddTag for each managed resource that has a field Spec.ForProvider.Tag to satisfy the generic interface Tagged.

It enables us to replace each specific tagger initializer that is currently copy-pasted for every controller with a central component reducing code redundancy.

The generated code abstracts from (most) of the more over a dozen tagging implementations that exist today. The following tag implementations are covered by this generator:

  • map[string]string
  • map[string]*string
  • []Tag {string, string}
  • []*Tag {string, string}
  • []Tag {*string, *string}
  • []*Tag {*string, *string}
  • []Tag (with string key and *string value)
  • []*Tag (with string key and *string value)

Note: It does not fix the issue that tags are defined differently for each resource because that is an issue with the underlying ACK generator and AWS SDK (see #1244).

This is a preliminary for #1306.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Unit tests

@MisterMX MisterMX marked this pull request as draft July 4, 2022 09:49
MisterMX added 2 commits July 8, 2022 01:48
Signed-off-by: Maximilian Blatt <[email protected]>
(external expert on behalf of DB Netz AG)
Add a `common.Tagger` to every resource that has a generated AddTag
method.

Signed-off-by: Maximilian Blatt <[email protected]>
(external expoert on behalf of DB Netz AG)
@MisterMX MisterMX force-pushed the codegen-tagged branch 4 times, most recently from fb1d147 to 5948f4f Compare July 8, 2022 14:50
@MisterMX MisterMX marked this pull request as ready for review July 11, 2022 11:41
@@ -16,21 +17,24 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE(negz): See the below link for details on what is happening here.
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
// // NOTE(negz): See the below link for details on what is happening here.
Copy link
Member

Choose a reason for hiding this comment

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

@MisterMX looks like we have double // now ?

@haarchri haarchri requested a review from muvaf July 23, 2022 11:54
@haarchri haarchri requested a review from chlunde August 8, 2022 17:54
@@ -0,0 +1,18 @@
/*
Copyright 2021 The Crossplane Authors.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: use 2022 for all new files?

*/

// Package common contains shared controller logic.
package common
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we call this something more specific like tagger or tagutil?
https://github.com/golang/go/wiki/CodeReviewComments#package-names

@chlunde
Copy link
Collaborator

chlunde commented Aug 8, 2022

looks awesome! I think we could add IsUpToDate helpers the same way later?


// AddTag adds a tag to this Key. If it already exists, it will be overwritten.
// It returns true if the tag has been added/changed. Otherwise false.
func (mg *Key) AddTag(key string, value string) bool {
Copy link
Collaborator

@chlunde chlunde Aug 8, 2022

Choose a reason for hiding this comment

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

is this one hand written? If so, add a comment why?

@chlunde
Copy link
Collaborator

chlunde commented Aug 8, 2022

@MisterMX did you also try some of the resource types in a real cluster?

This is a huge PR, it looks good to me but there might be a "needle in the haystack" here. Is there anything in particular you think we should look at, anything that's not tested or that you feel less confident about?

@artem-nefedov
Copy link

Will this fix inconsistency in tagging input? (like how most resources expect tags as an array, but some select ones, such as eks Cluster and NodeGroup, expect them to be a map)

@haarchri
Copy link
Member

haarchri commented Aug 9, 2022

@artem-nefedov no

@haarchri
Copy link
Member

@MisterMX can you rebase and Check for latest comments ? Thanks

@github-actions
Copy link

Crossplane does not currently have enough maintainers to address every issue and pull request. This pull request has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Adding a comment starting with /fresh will mark this PR as not stale.

@github-actions github-actions bot added the stale label Aug 23, 2023
@github-actions github-actions bot closed this Sep 6, 2023
@bjeevan-ib
Copy link

/fresh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants