-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#977 Enable validation of DI scopes in Kube
and PollKube
discovery providers
#2180
#977 Enable validation of DI scopes in Kube
and PollKube
discovery providers
#2180
Conversation
@raman-m, |
Kube
and PollKube
service providers
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'm not as confident as you; the proposed changes seem to be breaking ones.
- There's no acceptance test for the original user scenario in bug Cannot resolve scoped service
KubeClient.IKubeApiClient
from root provider #977.
In BDD, it's quite clear that we should test it first before any actual refactoring. - Why were so many changes proposed for a minor scope validation change? I don't understand.
I'm convinced that scope validation can be implemented with less code.
@@ -9,10 +11,23 @@ public static class OcelotBuilderExtensions | |||
public static IOcelotBuilder AddKubernetes(this IOcelotBuilder builder, bool usePodServiceAccount = true) | |||
{ | |||
builder.Services | |||
.AddKubeClient(usePodServiceAccount) | |||
.AddSingleton<IKubeApiClient, KubeApiClient>(KubeApiClientFactory) |
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.
It appears to be a breaking change 🤯 Lovely singletons once more❗
The main purpose of the Ocelot.Provider.Kubernetes
NuGet package is to facilitate the integration of the KubeClient
package with Ocelot
. The proposed changes undermine this objective by removing AddKubeClient
. This design direction is flawed because our solutions should be developed based on the official KubeClient
package's functionality, not by altering the library's behavior to suit our needs!
You have to understand that the issue is not AddKubeClient
extension, but singleton factory aka KubernetesProviderFactory.Get
with bad scope management!
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.
It appears to be a breaking change 🤯
Why is it a breaking change?
✔️ Public API hasn't changed
✔️ IKubeApiClient has the same singleton lifetime as it had before this fix(implicitly promoted)
Proposed change - make IKubeApiClient singleton lifetime explicit by registering it as singleton.
our solutions should be developed based on the official KubeClient package's functionality, not by altering the library's behavior to suit our needs!
KubeClient
package's functionality - talking to kube api as httpclient wrapper. I don't understand why it's lifetime can't be managed by Ocelot.Provider.Kubernetes
. (like it was done for consul).
test/Ocelot.AcceptanceTests/ServiceDiscovery/KubernetesServiceDiscoveryTests.cs
Outdated
Show resolved
Hide resolved
test/Ocelot.AcceptanceTests/ServiceDiscovery/KubernetesServiceDiscoveryTests.cs
Outdated
Show resolved
Hide resolved
test/Ocelot.UnitTests/Kubernetes/KubernetesProviderFactoryTests.cs
Outdated
Show resolved
Hide resolved
test/Ocelot.AcceptanceTests/ServiceDiscovery/KubernetesServiceDiscoveryTests.cs
Show resolved
Hide resolved
Initially, I was uncertain if the
Excellent! How did you validate this hypothesis? Theoretical assumptions differ from empirical testing. Additionally, as previously mentioned in this message, we will pursue alternative solutions, setting aside my
Using
If it's not implemented, why are we discussing it? You're correct to assume that we might encounter issues with disposed objects. Couldn't this be managed by
Please disregard the previous approach for Sergio; we will devise an alternative solution. I find these debates to be unproductive. |
There you are resolving
Usual
There is whole concept - HttpClientFactory that adresses this issues. Please read first 2 paragraphs. |
Kube
and PollKube
service providersKube
and PollKube
discovery providers
What's up, man? Are you online? |
Yes, I'm here. Fixed review comments, pointed why |
No! Because IKubeApiClient will be resolved once, stored inside Kube singleton, and then disposed after HttpContext gone. Provided test as proof. |
Well done, my astute developer! I concur, Why suggest refactoring everything for a minor issue that throws an I've asked you:
You didn't respond but instead advocated for your ideal solution, which I believe is commendable and, in my view, should have been implemented 3-5 years ago, utilizing a design based on singleton factories. Writing less code is possible by creating a fake scope and using it during the operation of reading the list of services, as suggested here, but sure you didn't like it. This approach is quite straightforward and minimalistic. However, sometimes proposing ideal solutions can be a waste of time. As I have previously mentioned, both
Code review has done. |
Successor |
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.
Ready for delivery ✅
@kick2nick Nikolay, |
* OcelotBuilderExtensionsTests for Eureka SD * BuildServiceProvider(true) #2179 (comment) * Add TestHostBuilder with enabled scopes validation by default across all testing projects #2179 (comment) * Update Sample projects with force scopes validation. Add Ocelot.Samples.Web project. Add OcelotHostBuilder and DownstreamHostBuilder helpers. Add Ocelot.Samples.Web project reference to all samples projects. TargetFramework is `net8.0` only.
Fixes #977
KubeClient.IKubeApiClient
from root provider #977Proposed Changes
Kube
&PollKube
providers can be resolved from DI with enabled scope validation.KubeApiClient
instead of manually created one. Enabled scope validation for ServiceProviderIKubeApiClient
singleton lifetime explicit.Successor
WatchKube
discovery provider #2174Docs