-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Shorter composite and composed resource names #1493
Conversation
if cp.GetRequirementReference() != nil && cp.GetRequirementReference().Name != "" { | ||
cd.SetGenerateName(cp.GetRequirementReference().Name + "-") | ||
} |
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.
Agree that this feels a little weird to sometimes name it one way and sometimes name it another.
@muvaf and I discussed this out of band today, and I wanted to capture an idea we had here. Historically we've automatically named dynamically provisioned managed resources (which are cluster scoped) This makes sense in some ways because the name reads left-to-right and thus sorts from least to most specific. Unfortunately it makes the name more likely to need truncation (because including the namespace makes it longer), and harder to truncate cleanly (because we'd truncate the most specific part of the name from the right). With composition we face the added concern that composites may be nested - is a composite resource can compose a composite resource. So if we stuck with Kubernetes convention we could end up with a name like I wonder if we can make use of labels to help with this? Perhaps something like:
I believe this would give us the following properties:
|
d4927ea
to
ab54740
Compare
cd20896
to
d526940
Compare
I have implemented this. All composite resources will first check whether they got the prefix label or not. If not, they'll label themselves with their name and use that label as prefix. This enables recursive application of the prefix. |
Now all of the members of a composition has got All manually tested. |
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.
@muvaf LGTM! Looks like it needs a minor rebase.
@@ -54,14 +63,25 @@ func (*DefaultConfigurator) Configure(cp resource.Composite, cd resource.Compose | |||
// Any existing name will be overwritten when we unmarshal the template. We | |||
// store it here so that we can reset it after unmarshalling. | |||
name := cd.GetName() | |||
namespace := cd.GetNamespace() |
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.
Will a composed resource ever have a namespace?
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.
It may or may not but I wanted that logic to be complete; we're setting the identifier in case template has something else and the identifier that can be overwritten is namespace + name
here, not necessarily name only. UID could be part of the template but that's a really far away case to cover.
…efix for the name of the composite resource Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
set a root name prefix label on composite to be used as prefix for all composed resources. Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
… name and namespace as label Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
…resources Signed-off-by: Muvaffak Onus <onus.muvaffak@gmail.com>
Description of your changes
Currently, the name of the composed resources get to be way too long for some provider validations, like
crossplane-system-myrequirement-sdas2-dsdh4
while it's not necessary to include the namespace as prefix and also yet another random string as postfix. With this change:myrequirement
myrequirement-dshn3
myrequirement-hdsn2
However, in Kubernetes, children resources have the name of their parents as prefix like:
deploymentname
deploymentname-dsjn3ndshh
deploymentname-dsjn3ndshh-idsjn
So, I think we should keep following the convention for composed resource name and make it
myrequirement-dshn3-hdsn2
, however, this increases the likeliness of failure in name validation of managed resources since it's longer; see crossplane-contrib/provider-gcp#222 and crossplane/stack-azure-sample#26 . In practice, it's fine if we have only one rand string set but it's against the convention.I think we should do the truncation for
external-name
annotation generation as proposed in crossplane-contrib/provider-gcp#222 (comment) . So, I'll keep this in draft until we resolve that discussion. If we do the truncation, then it should be fine to keep the convention.Fixes #1598
How has this code been tested?
Checklist
I have:
make reviewable
to ensure this PR is ready for review.appropriate.
For more about what we believe makes a pull request complete, see our
definition of done.