-
Notifications
You must be signed in to change notification settings - Fork 592
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
Feat/ingress class driven configuration #1586
Feat/ingress class driven configuration #1586
Conversation
…setting the upstream for an endpoint
"Do not merge" yet because this will not go to KIC 2.0, and |
Codecov Report
@@ Coverage Diff @@
## next #1586 +/- ##
===========================================
- Coverage 50.47% 37.54% -12.94%
===========================================
Files 92 96 +4
Lines 6437 6438 +1
===========================================
- Hits 3249 2417 -832
- Misses 2880 3854 +974
+ Partials 308 167 -141
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
The approach seems good 👍. First round of comments follows.
@@ -384,12 +399,11 @@ func getEndpoints( | |||
Port: fmt.Sprintf("%v", targetPort), | |||
}) | |||
} | |||
if annotations.HasServiceUpstreamAnnotation(s.Annotations) { | |||
if annotations.HasServiceUpstreamAnnotation(s.Annotations) || ingressClassParams.ServiceUpstream { |
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.
I recommend that we isolate the logic of "evaluating whether a service should be treated as service-upstream or not" in a separate, unit-tested function. That would mean putting the condition of this if
expression in a function.
Note that this comment interacts with the comment about the signature of getEndpoints
above.
@@ -102,6 +102,15 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy | |||
Proxy: proxy, | |||
}, | |||
}, | |||
{ | |||
IsEnabled: &alwaysEnabled, |
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.
This won't work for kubernetes <1.18 because they don't support the IngressClass
kind.
Please target not breaking compatibility with k8s 1.16+.
The simplest way to go about that would be by exposing a flag to control whether KIC shall try listening to IngressClass
es.
Then (outside of the scope of this PR) we could implement a mechanism (an AutoHandler most likely - there is some work in progress on it, see #1585) - that would tell whether the apiserver supports IngressClass
es and react dynamically. But, again, this would be outside of the scope of this PR.
@@ -153,6 +162,15 @@ func setupControllers(logger logr.Logger, mgr manager.Manager, proxy proxy.Proxy | |||
IngressClassName: c.IngressClassName, | |||
}, | |||
}, | |||
{ | |||
IsEnabled: &c.IngressClassParamsEnabled, |
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.
non-blocking, open question sparked by my comment above: I'm wondering whether two different flags for IngressClass
and IngressClassParams
make sense, or should it be just one.
@@ -35,6 +35,7 @@ const ( | |||
const ( | |||
IngressClassKey = "kubernetes.io/ingress.class" | |||
KnativeIngressClassKey = "networking.knative.dev/ingress.class" | |||
KongIngressClassKey = "ingress.konghq.com/ingress.class" |
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.
Following an out-of-band discussion: the controller name in the IngressClass
resource is unused by KIC. Please use an "unused"
const in tests instead, because a value like this may bring confusion to users, and also it's very similar to the name of the ingress class annotation.
@@ -330,7 +331,8 @@ func getServiceEndpoints(log logrus.FieldLogger, s store.Storer, svc corev1.Serv | |||
// check all protocols for associated endpoints | |||
endpoints := []util.Endpoint{} | |||
for protocol := range protocols { | |||
newEndpoints := getEndpoints(log, &svc, servicePort, protocol, s.GetEndpointsForService) | |||
ingressClassParams := getIngressClassParamsOrDefault(s) | |||
newEndpoints := getEndpoints(log, &svc, servicePort, protocol, s.GetEndpointsForService, ingressClassParams) |
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.
I think that a serviceUpstream bool
parameter would produce a cleaner solution than plumbing the ingress class params through. Also it would allow for better separation of concerns between "ingress class parameterization" and "extracting info from a service".
Suggestion: replace IngressClassParams
with a bool
saying whether getEndpoints
shall yield a single service upstream endpoint, or the real service endpoints.
ingressClassParams: []*kongv1alpha1.IngressClassParams{}, | ||
ingressClasses: []*networkingv1.IngressClass{}, |
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.
ingressClassParams: []*kongv1alpha1.IngressClassParams{}, | |
ingressClasses: []*networkingv1.IngressClass{}, |
two comments here:
nil
slices are better than empty literal slices, because the latter occupy memory unnecessarily- there's no need to initialize empty slices explicitly
https://medium.com/@habibridho/golang-nil-vs-empty-slice-87fd51c0a4d
Please follow this style throughout the PR.
shouldExist bool | ||
}{ | ||
{ | ||
name: "When there are no ingress classes defined", |
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.
"When there is" is superfluous - keep the descriptions simple: e.g. no ingress class defined
Name: "meant-for-a-different-ingress-controller", | ||
}, | ||
Spec: networkingv1.IngressClassSpec{ | ||
Controller: "some/ingress-controller", |
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.
please say "unused" here - like explained in one of the comments above
metadata: | ||
name: foo | ||
spec: | ||
controller: "some/controller" |
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.
"unused" - as said in other comments
// by the IngressClass resource associated with this controller, if it exists. | ||
// Otherwise, it returns an error | ||
func (s Store) GetIngressClassParams() (*kongv1alpha1.IngressClassParams, error) { | ||
class, exists, err := s.stores.IngressClass.GetByKey(s.ingressClass) |
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.
There's a NPE in the tests on this line - please ensure that all the CI tests for this PR pass.
@larribas so that you're aware we made some structural changes in I've created the following branch: |
GH has automatically closed this PR because we've deleted the Could you please change the target branch of this PR from edit: apparently, in this case GH doesn't allow for changing the target branch. If you are unable to set the target branch to |
This is a proposal to allow cluster operators to control certain settings of an ingress controller through a new CR named
IngressClassParams
, which must be associated to the controller through anIngressClass
.The motivation behind this ticket and the choice to do it through the
IngressClass
is explained in detail in issue #1131.The
IngressClassParams
CR has been introduced at versionv1alpha1
, and covering only one setting (serviceUpstream
). The idea is that the same CR can be extended to support all existing controller-level configuration options.Which issue this PR fixes:
Closes #774
Closes #1131
Special notes for your reviewer:
This is my first time contributing to the codebase. I have a few follow-up questions, mostly about conventions.
serviceUpstream
is set to true in theIngressClassParameters
but theingress.kubernetes.io/service-upstream
annotation is explicitly set to false?IngressClassParams
with Kong? Why is there a convention to prefix resources with Kong when they're already in kong's api group? Does the convention apply in this case?PR Readiness Checklist:
The following tasks are left unfinished (to be done after the first review):
CHANGELOG.md
release notes have been updated to reflect any significant (and particularly user-facing) changes introduced by this PR