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

Implement GetExternalTags #123

Merged
merged 1 commit into from
Mar 4, 2020
Merged

Implement GetExternalTags #123

merged 1 commit into from
Mar 4, 2020

Conversation

muvaf
Copy link
Member

@muvaf muvaf commented Feb 28, 2020

Description of your changes

Implement GetExternalTags to return Crossplane tags for managed resource controllers to tag their external resources.

Makes it easier to implement https://github.com/crossplane/crossplane/blob/master/design/one-pager-managed-resource-api-design.md#external-resource-labeling

Checklist

I have:

  • Run make reviewable to ensure this PR is ready for review.
  • Ensured this PR contains a neat, self documenting set of commits.
  • Updated any relevant documentation, examples, or release notes.
  • Updated the RBAC permissions in clusterrole.yaml to include any new types.

@muvaf muvaf requested review from negz and hasheddan February 28, 2020 13:48
@muvaf
Copy link
Member Author

muvaf commented Feb 28, 2020

I thought I opened the PR but seems like forgot to click the button :(

@negz @hasheddan I was thinking about adding the following labels, too, to make it possible do more detailed resource filterin in cloud provider:

  • crossplane.io/class
  • crossplane.io/provider

What do you guys think?

Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

This looks pretty good so far! For the other two proposed tags:

  1. Class tag: I am not sure how much longer are current class structure will be relevant so might hold off on that one.
  2. Provider tag: Assuming this would be the name of the literal provider object? If so I think that could be useful!

@muvaf
Copy link
Member Author

muvaf commented Feb 28, 2020

Class tag: I am not sure how much longer are current class structure will be relevant so might hold off on that one.

Well, be it class or some other thing, I think we'll have something that serves as resource class. So, it might be worth adding it now and change the string if the name changes.

Provider tag: Assuming this would be the name of the literal provider object? If so I think that could be useful!

Yes, it's literal object name.

@hasheddan
Copy link
Member

That sounds fine. Another thing that makes class different is that statically provisioned managed resources do not have a class ref while the other 3 tags are values that are always present.

@muvaf
Copy link
Member Author

muvaf commented Mar 2, 2020

Another thing that makes class different is that statically provisioned managed resources do not have a class ref while the other 3 tags are values that are always present.

Yeah, I imagine we'd just skip class label in that case.

I'll circle back to API patterns doc and add these if everyone is onboard. @negz what do you think?

Copy link
Member

@negz negz left a comment

Choose a reason for hiding this comment

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

Thanks @muvaf!

pkg/resource/resource.go Outdated Show resolved Hide resolved
// resource in provider API.
func GetExternalTags(mg Managed) map[string]string {
tags := map[string]string{
ExternalResourceKindTagKey: mg.GetObjectKind().GroupVersionKind().GroupKind().String(),
Copy link
Member

Choose a reason for hiding this comment

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

Can we rely on this field always being set? I recall it was being automatically cleared by some clients, apparently intentionally, which is why most of our crossplane-runtime functions that need a GVK require we pass either a GVK or a scheme to determine one. kubernetes-sigs/controller-runtime#528 indicates that the old behaviour I described may now be gone.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will test it and write here. I simply relied on the fact that all those functions returned non-pointer objects.

Copy link
Member Author

Choose a reason for hiding this comment

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

Verified that it does return GVK correctly.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! This might allow us to simplify some of our functions in pkg/meta (and possibly pkg/resource?) that assume they can't rely on GetObjectKind to actually return the kind of an object.

@muvaf
Copy link
Member Author

muvaf commented Mar 3, 2020

@hasheddan @negz Heads-up, I'm replacing / with - as it seems / in tag key is only accepted by AWS and hyphen is accepted by all three. See the restrictions for each:

@muvaf
Copy link
Member Author

muvaf commented Mar 3, 2020

Alright, . is not supported by GCP. What do you think about crossplane-kind, crossplane-class etc ?

Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

@muvaf those sound good to me!

@negz
Copy link
Member

negz commented Mar 4, 2020

Looks like this needs to be rebased - I'll merge once the branches align.

…rce controllers to tag their external resources

Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
@muvaf
Copy link
Member Author

muvaf commented Mar 4, 2020

@negz ready to go! I added a small change to make kind lowercase(checked kinds are not case-sensitive) to comply with GCP more easily without breaking anything.

@negz negz merged commit e98175f into crossplane:master Mar 4, 2020
@muvaf muvaf deleted the labels branch March 4, 2020 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants