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

Retrieve ports for rules that use ExternalName Services #985

Merged
merged 5 commits into from
Dec 11, 2020

Conversation

rainest
Copy link
Contributor

@rainest rainest commented Dec 10, 2020

What this PR does / why we need it:
ExternalName Services have no ports of their own. They only receive ports when combined with an Ingress rule that specifies them.

findPort() currently returns an error if no port is available on the Service. ExternalName Services will thus always return the no port error.

This change adds the 0.8 logic for ExternalName Services to findPort(), which just builds a ServicePort from the requested port. It returns errors from the non-numeric port cases indicating that they are not valid for ExternalNames.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #984

Travis Raines added 2 commits December 10, 2020 12:03
Add findPort() logic to return a port for an ExternalName Service
definition. As these have no ports of their own, we simply return
whichever port the Ingress rule requested.

Fix #984
mflendrich
mflendrich previously approved these changes Dec 11, 2020
Copy link
Contributor

@mflendrich mflendrich left a comment

Choose a reason for hiding this comment

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

LGTM, one nit attached (and considerations below).

I am concerned about introduction of TCP here - the information passed to findPort is not sufficient to determine the protocol; we should be cautious about such silent assumptions if we're willing to add UDP support (#925) soon (I know that the former implementation had TCP hardcoded here).

If you have an idea how to avoid TCP here, please consider changing the solution that way. Otherwise good to go.

internal/ingress/controller/parser/parser.go Outdated Show resolved Hide resolved
Co-authored-by: Michał Flendrich <[email protected]>
@rainest
Copy link
Contributor Author

rainest commented Dec 11, 2020

I think we're kinda just stuck there--ExternalName doesn't specify protocol information either (honestly, it kinda feels like it should include port and protocol information, for exactly this kind of hinting). It may not matter, however, since we're using this to build Kong upstreams, which don't actually care about protocol: their targets are just host/IP+port combinations, with the actual protocol determined by the Kong service using the upstream.

We still need protocol information for constructing the Kong service, and the existing implementation of that is a mixed bag: it's determined by the konghq.com/protocol annotation (with an effective http default) or via dedicated logic for the Ingress-like resource that uses it. A future UDPIngress will presumably use something similar to the TCPIngress service construction code that just assumes the protocol without caring about the underlying K8S Service.

Kinda convoluted and messy (more evidence for why Service APIs are needed to radically revamp this ecosystem), but I think it's fine to leave the stub configuration here since we'll ignore it when creating the Kong configuration later anyway.

// We must assume that the user-requested port is valid and construct a ServicePort from it
if svc.Spec.Type == corev1.ServiceTypeExternalName {
return &corev1.ServicePort{
Protocol: "TCP",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Protocol: "TCP",

Copy link
Contributor

Choose a reason for hiding this comment

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

@rainest

I think it's fine to leave the stub configuration here since we'll ignore it when creating the Kong configuration later anyway

In such case we should be able to remove the protocol field whatsoever, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. Tests pass with it gone, but our coverage isn't great, and my concern is that there's something elsewhere that will try to make use of it and panic if it's nil. The original 0.8 code did include it, so IMO safest thing is to just let that persist. However, grep doesn't show anything in our code that looks like it could use it.

@rainest rainest merged commit bf755d9 into main Dec 11, 2020
@rainest rainest deleted the fix/externalname-port branch December 11, 2020 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.10+ port checks break ExternalName Services
2 participants