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

Generate backendservice name if not specified in autoneg annotation #44

Merged

Conversation

fdfzcq
Copy link
Contributor

@fdfzcq fdfzcq commented Aug 12, 2021

Why

We (Fabric/Spotify) would like to use autoneg without specifying neg names and realized that the default values might be a bit simple and prone to name collisions. Currently the NEG name defaults to service name + port when using new autoneg annotation and service name when using old config, in this PR we propose to change it to generated name similar to how k8s-io/ingress-gce generates NEG names.

What

  • Allows passing a NEG name template using --neg-name-template flag, and defaults to {name}-{port}
  • If NEG name is not set in the new autoneg annotation, generate one using the given template
    • Generated name may contain namespace, name, port or the first 8 characters of a sha256 hash, separated with -. It has max length of 63 characters, the non-hash tags are truncated evenly if the full name is longer than that. The hash can be used to make sure truncated long names won't collide.
    • The name generation is only applied to the new neg annotation as port mapping is missing with the old annotation.

@google-cla
Copy link

google-cla bot commented Aug 12, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

// {namespace}-{name}-{service port}-{hash}
//
// Output name is at most 63 characters.
func generateNegName(namespace string, name string, portStr string) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Erik suggested that we could import k8s-io/ingress-gce and call Namer directly. I tried this at first and got this error, suggesting using k8s-io/ingress-gce as a dependency is discouraged. There is a workaround linked in the issue but it's neater to move the functionalities here.

@rosmo
Copy link
Collaborator

rosmo commented Aug 12, 2021

Hey @fdfzcq and thank you for the PR! I was wondering if this could be a bit more flexible and I had two ideas in mind:

  • Allow passing a template to the controller via command line parameters (eg. {namespace}-{name}-{port}-{hash}), and/or:
  • Allow setting/overriding the template via annotation on the namespace

I think the first one ought to be fairly trivial, so I'd probably go with that (would also allow to keep backwards compatibility, if the default template was {name}-{port}), second one I'm not so sure of (if it's even desirable). Wdyt?

@fdfzcq
Copy link
Contributor Author

fdfzcq commented Aug 12, 2021

Thanks @rosmo
That sounds good, do you mean supporting something like --neg-name-template={name}-{port}-{hash} here ?

@rosmo
Copy link
Collaborator

rosmo commented Aug 12, 2021

@fdfzcq Yes, exactly there!

@google-cla
Copy link

google-cla bot commented Aug 12, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@fdfzcq fdfzcq marked this pull request as ready for review August 13, 2021 07:08
@fdfzcq
Copy link
Contributor Author

fdfzcq commented Aug 13, 2021

@rosmo I've added configurable template, could you take a look when you have time? Thanks! :)

main.go Outdated Show resolved Hide resolved
@soellman
Copy link
Contributor

Thanks Sophy! I'll review this tomorrow.

Question - would you also want a flag that disallows setting the service name? I could see how that might be desirable so that all users would have their service names automatically determined.

@fdfzcq
Copy link
Contributor Author

fdfzcq commented Aug 16, 2021

@soellman Thank you Oliver, yes we think something to disallow setting the service name would be nice to have.

Copy link
Contributor

@soellman soellman left a comment

Choose a reason for hiding this comment

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

This is a solid and clear PR, thank you, this look great.

I have one request that will require some name changes: please let's change "neg name template" to "service name template" everywhere, as this better describes what we'll use the name to describe. We could also change the command line flag to "default-backendservice-name" as well.

If you like, you could also add a flag that disables the ability to specify a service name (something like --disable-supplied-service-names), or we can add this in a future PR.

Thanks!

main.go Outdated Show resolved Hide resolved
@fdfzcq
Copy link
Contributor Author

fdfzcq commented Aug 17, 2021

Thanks @soellman I've changed the flag to default-backendservice-name now and we can make another PR to add disable-service-name flag.

@fdfzcq
Copy link
Contributor Author

fdfzcq commented Aug 17, 2021

@googlebot I signed it!

main.go Outdated
@@ -73,6 +78,12 @@ func main() {
os.Exit(1)
}

if !controllers.IsValidServiceNameTemplate(serviceNameTemplate) {
err = fmt.Errorf("invlaid service name template %s", serviceNameTemplate)
Copy link
Contributor

Choose a reason for hiding this comment

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

small typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops thx, I forgot this :D

@soellman soellman changed the title Generate neg name if not specified in autoneg annotation Generate backendservice name if not specified in autoneg annotation Aug 17, 2021
Copy link
Contributor

@soellman soellman left a comment

Choose a reason for hiding this comment

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

Looks great, thanks again for the contribution!

@soellman soellman merged commit 97161bd into GoogleCloudPlatform:master Aug 17, 2021
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