-
Notifications
You must be signed in to change notification settings - Fork 698
Allow limiting Contour to watch certain namespaces #5214
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
Conversation
666138d
to
9efccd6
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5214 +/- ##
==========================================
- Coverage 78.30% 78.18% -0.12%
==========================================
Files 138 138
Lines 18450 18480 +30
==========================================
+ Hits 14447 14449 +2
- Misses 3727 3755 +28
Partials 276 276
|
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.
Looks very good to me 👍 Added few questions inline.
test/e2e/httpproxy/httpproxy_test.go
Outdated
@@ -444,7 +444,7 @@ descriptors: | |||
} | |||
}) | |||
|
|||
f.NamespacedTest("root-ns-crd", testRootNamespaces(rootNamespaces)) | |||
f.NamespacedTest("nonroot-ns-crd", testRootNamespaces(rootNamespaces)) |
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 was first bit confused about why the root
to nonroot
change 😅 At first sight, it seemed to go against the naming convention used in the test cases. But I see it: The namespace argument of NamespacedTest()
has always been used to test the negative case i.e. root proxy is in non-root namespace.
I know this is old existing test case, not part of this PR, but maybe a tiny comment could be added to clarify?
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.
Yeah it was a bit confusing for me at first as well, hence the renaming. I'll refactor it further so that it's no longer a magic string.
// Proxy in non-watched namespace should fail | ||
deployEchoServer(f.T(), f.Client, nonWatchedNS, "echo") | ||
p := newEchoProxy("proxy", nonWatchedNS) | ||
_, ok := f.CreateHTTPProxyAndWaitFor(p, e2e.HTTPProxyNotReconciled) |
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 wonder if this would catch a failure? Or will it always likely return ok=true
immediately, since newly created resource would have NotReconciled
by default, before being updated by the controller? It might be a race between test and the controller.
When the default state is also the expected state, I guess test should poll until value is considered stable. I do not see such variant of wait.PollNnn()
in k8s.io/apimachinery/pkg/util/wait
and I'm quite uncertain if it is worth the effort to even look for, since the "real test" would be anyways to deploy with Role/RoleBinding
RBAC. The lack of status updates is of course a good secondary indication that ClusterRoles
were not used 😄
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, the resource would ideally always be NotReconciled
because nobody would update it...
I suggest that we still have the negative test because otherwise the happy case is not that trustworthy. We can use wait.Poll
with a sufficient interval
parameter, since the function will automatically wait one interval before doing the first poll. But we also don't want the test case to run too long. I feel like the controller is fairly quick, so if we set the interval to let's say 10 seconds, we can be fairly certain that the resource should have updated by then (if the controller code was misbehaving). Of course, this is not fool proof but better than nothing (?).
9efccd6
to
7309959
Compare
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.
Thanks @nsimons, this looks pretty good to me, couple comments below
5d7d132
to
c3b749e
Compare
Thanks for the updates @nsimons - I think this looks good, would just like to poke around with testing a little bit more, but we should be able to get this into the upcoming release |
One note: if |
Hmm, right. We could force the user to give the namespace in It depends which use cases we want to support. From the related issues I think the most common scenario will be that everything is located within the same namespace (Contour, Envoy, application). Another one that we can foresee is that Contour+Envoy is in an infra namespace and the app is somewhere else. In that case it's probably okay that Contour watches both infra and app namespaces, even if we don't expect any resources in infra ns. |
Yeah, thinking some more I think it's fair to say that if you want the Envoy service to be watched, you need to include it. Let's just see if we can find a place to explicitly document this -- I'm thinking maybe |
xref #5099 (comment) -- so looks like:
|
I did not find a way to achieve both goals with the current version. I submitted question kubernetes-sigs/controller-runtime#2273 asking for help. I tested the main branch of controller-runtime and I can confirm it solves the problem. I stored a diff of my experiment here https://gist.github.com/tsaarni/94184af509664334e0b3350c9c0ac86a. The project is going through API refactoring and few changes were required around the code base. |
I got confirmation that it is not possible as of today. Though I'm not absolutely 100% certain if one could hack around the limitation, maybe one could reproduce some larger part of the builder logic on Contour side... The API in |
So sounds like we may have to pick/choose between #5214 and #5099 for the upcoming Contour 1.25, and then plan to refactor later to support both. @tsaarni @nsimons what are your thoughts on priority between the two? From my perspective #5099 would be higher priority, but would like your take as well. |
personally +1 on #5099 since that can have a wider benefit for users, but can be swayed as well |
We discussed this with @nsimons. Maybe there could be one option that would allow doing both, with one limitation: Background Currently controller-runtime allows setting single namespace Proposal In the 1st phase we could limit #5214 to single namespace. When controller-runtime releases the new API, we could have 2nd phase that allows multiple namespaces to be watched. Multiple namespaces can be useful since it allows "cross-namespace" features to work, even when Contour is not granted cluster roles. Alternative 1: We could keep Alternative 2: We could change it to For our own use case the limitation of single namespace would be completely OK. If we agree on the approach, @nsimons promised to make the changes to this PR on top of #5099, so we could work on the memory footprint issue first. |
I'm down with this proposal, and Alternative 1 (if we want to do 2 we could make the flag like |
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.
relevant to this PR, this issue has some comments and links with details on the next controller-runtime release date and release notes: kubernetes-sigs/controller-runtime#2295
Thanks Sunjay. I think it's better that we wait for controller-runtime 0.15.0 which contains the full multi-namespace support. Then we can merge this PR almost as-is. It should be released quite soon as far as I understood. I started to bump and test the alpha version in a related PR. |
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.
LGTM 👍
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.
LGTM, thanks @nsimons!
Signed-off-by: Niklas Simons <[email protected]>
Signed-off-by: Niklas Simons <[email protected]> Signed-off-by: shadi-altarsha <[email protected]>
Signed-off-by: Niklas Simons <[email protected]>
This PR is a continuation of #5002 with added checks, test cases and documentation.
Fixes #2497
Fixes #4899
Signed-off-by: Niklas Simons [email protected]