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
CancellationToken
support and a lot of async improvements
#725
CancellationToken
support and a lot of async improvements
#725
Conversation
c5ca283
to
c9082a8
Compare
c9082a8
to
b12f14b
Compare
CancellationToken
support and a lot of async improvements
b12f14b
to
becd43c
Compare
Hey @nachtjasmin I don't mind breaking changes at all. While I'm reviewing the stuff, the linter is ranting about some things it seems. Another general comment: Why do we need factories? Personally I'm not really a fan of factories. Is there a specific use-case / reason for them? |
src/KubeOps.Abstractions/Finalizer/IEventFinalizerAttacherFactory.cs
Outdated
Show resolved
Hide resolved
test/KubeOps.Operator.Test/Controller/CancelEntityRequeue.Integration.Test.cs
Outdated
Show resolved
Hide resolved
test/KubeOps.Operator.Test/Events/EventPublisher.Integration.Test.cs
Outdated
Show resolved
Hide resolved
The linter seems to be angry with you... |
BREAKING: This changes the interface signature of IKubernetesClient.
BREAKING: The signature changes for derived classes.
c72dd5e
to
32a34c5
Compare
The joy of line endings. Running |
all fingers crossed. |
{ | ||
public Task ReconcileAsync(V1TestEntity entity, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Reconciling entity {Entity}.", entity); |
Check failure
Code scanning / CodeQL
Log entries created from user input
|
||
public Task DeletedAsync(V1TestEntity entity, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Deleted entity {Entity}.", entity); |
Check failure
Code scanning / CodeQL
Log entries created from user input
{ | ||
public async Task ReconcileAsync(V1TestEntity entity, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Reconciling entity {Entity}.", entity); |
Check failure
Code scanning / CodeQL
Log entries created from user input
|
||
public Task DeletedAsync(V1TestEntity entity, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Deleting entity {Entity}.", entity); |
Check failure
Code scanning / CodeQL
Log entries created from user input
{ | ||
public Task ReconcileAsync(V1TestEntity entity, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Reconciling entity {Entity}.", entity); |
Check failure
Code scanning / CodeQL
Log entries created from user input
|
||
public Task DeletedAsync(V1TestEntity entity, CancellationToken cancellationToken) | ||
{ | ||
logger.LogInformation("Deleted entity {Entity}.", entity); |
Check failure
Code scanning / CodeQL
Log entries created from user input
Hey @nachtjasmin Do you have any idea, why the tests won't start? It seems, that the host does not start in test mode. The debug output of the github actions:
|
Not at all, but I'll try to fix it. ^^ |
If I can be of any help, just say the word. I try to fetch your fork and run the tests locally. |
Head branch was pushed to by a user without write access
At least with the local KinD cluster and with act, the tests are working again. The After that, I plan to rewrite the commit history to ensure a clean history. Gonna let you know when I'm done with that, just so you don't have to accept my WIP commits all the time. 😄 |
Nice work, thank you :-) Don't worry about the commits, they're gonna be squashed anyway. |
And thank you for your effort! |
The previous implementation effectively enforced that a Kubernetes cluster is present. While this is acceptable for the production environment, it made integration testing much harder. By adding several factories for publishers, attachers and the requeue delegates, we can now mock those tasks as well. Furthermore, the leader election is no longer done during the creation phase, instead it's now implemented as one additional background service.
The synchronous event-based implementations were replaced by two separate, now asynchronous IHostedService services. One is responsible for watching the resources while the other is watching the queue for manual requeues. The queue for requeueing entities is now asynchronous as well and instead of creating multiple timers, it leverages Task.Delay and the CancellationTokenSource. Also, finalizer registrations are taking advantage of the ability to store keyed services in the DI container.
We don't wanna let run the tests forever, a generous timeout of 30 seconds should be suitable for most cases.
This reverts commit 6078151.
90074f9
to
81a74fd
Compare
Well, if the commits are squashed anyway, I think I'm done now. :D (note to self: make smaller PRs next time 🙈) |
The linter is still yapping, but I'll fix the issues right away. |
aaah, sorry >< |
This PR adds the ability to cancel (almost) all asynchronous operations with the built-in
CancellationToken
. Due to the nature of interfaces, almost all of those changes are breaking the existing API.It also adds an
WatchAsync
method to theIKubernetesClient
, which is making use of the newer asynchronous enumerables.I tried to keep it as backwards-compatible as possible, however, this was not possible due to different problems. Most notably, the interfaces no longer have a default implementation to actually break existing code instead of failing silently. If I would've just changed the existing interface (with
Task.CompletedTask
as the return , current implementations ofReconcileAsync
would have not been called anymore. Therefore I removed the default implementations to ensure that all remaining controllers get updated.Note about the one failing test
During local development with a kind cluster, I could not get the
KubeOps.Operator.Test.Events.EventPublisherIntegrationTest.Should_Increase_Count_On_Existing_Event
to run successfully. It always broke with some certification error, other tests work fine tho. I could not determine whether it is an issue with the kind cluster or some other error.