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 load-balancer-name-prefix annotation #3684

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hfern
Copy link

@hfern hfern commented May 8, 2024

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:

image

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

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested - make test and reviewed generated docs so they look right
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hfern
Once this PR has been reviewed and has the lgtm label, please assign m00nf1sh for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

linux-foundation-easycla bot commented May 8, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label May 8, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @hfern!

It looks like this is your first PR to kubernetes-sigs/aws-load-balancer-controller 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/aws-load-balancer-controller has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 8, 2024
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels May 8, 2024
}
if len(explicitNames) > 1 {
return "", errors.Errorf("conflicting load balancer name: %v", explicitNames)
Copy link
Author

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.

@@ -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.
Copy link
Collaborator

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?

Copy link
Author

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)
Copy link
Collaborator

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.

Copy link
Author

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) {
Copy link
Collaborator

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()

Copy link
Author

Choose a reason for hiding this comment

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

✅ Done

@oliviassss
Copy link
Collaborator

Thanks for the contribution, and sorry for the delay. I left some minor comments. Also, can you please add an e2e test to ingress?

@hfern
Copy link
Author

hfern commented May 24, 2024

@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?

@hfern hfern requested a review from oliviassss May 24, 2024 18:56
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 31, 2024
@k8s-ci-robot
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants