-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 load-balancer-name-prefix
annotation
#3684
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hfern The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @hfern! |
Hi @hfern. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
} | ||
if len(explicitNames) > 1 { | ||
return "", errors.Errorf("conflicting load balancer name: %v", explicitNames) |
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.
Since this block of code would have to be duplicated for the prefix annotation, I just moved it to a new getNameAnnotation
and parameterized the annotation name.
docs/guide/ingress/annotations.md
Outdated
@@ -176,6 +177,20 @@ Traffic Routing can be controlled with following annotations: | |||
alb.ingress.kubernetes.io/load-balancer-name: custom-name | |||
``` | |||
|
|||
- <a name="load-balancer-name-prefix">`alb.ingress.kubernetes.io/load-balancer-name-prefix`</a> specifies the custom name prefix to use for the load balancer. The provided value will have 11 characters appended to it for uniqueness. Prefixes longer than 21 characters will be treated as an error. |
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.
just for my understanding why is it 11 as the limit?
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.
AWS limits load balancer names to 32 characters. I kept the existing 11 character random suffix (a dash plus 10 random characters). I will update this line of documentation to reflect that the limitation comes from the underlying lb name constraints.
if len(explicitNames) > 1 { | ||
return "", errors.Errorf("conflicting load balancer name: %v", explicitNames) | ||
|
||
prefixName, err := t.getNameAnnotation(annotations.IngressSuffixLoadBalancerNamePrefix, maximumLoadBalancerNameLength-11) |
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.
nit: maybe change the 11
to a constant instead of hard coded here.
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.
Good point
@@ -123,6 +121,30 @@ func (t *defaultModelBuildTask) buildLoadBalancerName(_ context.Context, scheme | |||
return fmt.Sprintf("k8s-%.8s-%.8s-%.10s", sanitizedNamespace, sanitizedName, uuid), nil | |||
} | |||
|
|||
func (t *defaultModelBuildTask) getNameAnnotation(annotationName string, maxLength int) (string, error) { |
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.
nit: maybe rename to parseNameOrNamePrefixFromAnnotation()
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.
✅ Done
Thanks for the contribution, and sorry for the delay. I left some minor comments. Also, can you please add an e2e test to ingress? |
@oliviassss thanks for taking a look at this -- I added an e2e test that exercised the prefix annotation and addressed the other PR comments. Can you take another look when you get a chance? |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Issue
Description
This adds a
alb.ingress.kubernetes.io/load-balancer-name-prefix
annotation. This is useful for being able to control the name of the created load balancer without needing to specify a fully unique name.We have several similar clusters in one AWS account, all with similar namespace/resources. This leads to this situation, where it's hard to tell at a glance (without digging into tags) which load balancer goes to which cluster:
Already the ALBC will provide uniqueness for you if you do not specify a name. This is nice because you can be reasonable certain there will be no name collisions. That means you can copy/paste (and we can vend) a static piece of yaml into different clusters or namespaces IF you do not specify the
load-balancer-name
.However, if you want to get more descriptive with the name via
load-balancer-name
, now you need to worry about collision (even potentially with resources in other clusters).load-balancer-name-prefix
is a happy middle ground where you can be more specific without having to own avoiding naming collisions.Checklist
README.md
, or thedocs
directory)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯