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

install watch reaction function to fake client #550

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AshishNaware
Copy link

This PR adds ability to install watch reaction function to the fake client. This will help in writing tests where its required to simulate behavior of the watcher.

@AshishNaware AshishNaware force-pushed the support_watch_reactions branch from c189e97 to c533767 Compare October 5, 2024 02:04
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 58.85%. Comparing base (7437a9b) to head (c533767).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
testing/config.go 0.00% 2 Missing and 1 partial ⚠️
testing/client.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #550      +/-   ##
==========================================
- Coverage   58.93%   58.85%   -0.09%     
==========================================
  Files          33       33              
  Lines        2981     2987       +6     
==========================================
+ Hits         1757     1758       +1     
- Misses       1130     1134       +4     
- Partials       94       95       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@scothis
Copy link
Member

scothis commented Oct 7, 2024

Hi @AshishNaware. Thanks for the contribution. This change is heading in the right direction, but is also incomplete as it has no runtime effect. WithWatchReactors needs to be plumbed into the test cases (ReconcilerTestCase/SubReconcilerTestCase/AdmissionWebhookTestCase) the same way WithReactors is. That part is relatively simple. The more complicated part will be consuming the WatchReactionFunc. The client wrapper doesn't currently implement Watch that method will need to be implemented and consume the reaction funcs. The DuckAwareClientWrapper also needs to have Watch added.

Let me know if you need any pointers into the code base.

@AshishNaware
Copy link
Author

Hi @AshishNaware. Thanks for the contribution. This change is heading in the right direction, but is also incomplete as it has no runtime effect. WithWatchReactors needs to be plumbed into the test cases (ReconcilerTestCase/SubReconcilerTestCase/AdmissionWebhookTestCase) the same way WithReactors is. That part is relatively simple. The more complicated part will be consuming the WatchReactionFunc. The client wrapper doesn't currently implement Watch that method will need to be implemented and consume the reaction funcs. The DuckAwareClientWrapper also needs to have Watch added.

Let me know if you need any pointers into the code base.

Hey. Thanks for the feedback. Let me dig more into the code-base. I will create a thread here if i have any questions :)

@AshishNaware
Copy link
Author

@scothis - I just took a quick glance at the code and I see a Watch method already implemented for duckAwareClientWrapper that returns a watch.Interface. I assume that we need a similar implementation for the clientWrapper as well. thoughts?

@scothis
Copy link
Member

scothis commented Oct 8, 2024

I assume that we need a similar implementation for the clientWrapper as well. thoughts?

Yep. This is also where the watch reaction funcs should be applied.

@AshishNaware AshishNaware force-pushed the support_watch_reactions branch from c533767 to 16e49a3 Compare January 23, 2025 03:09
@AshishNaware AshishNaware force-pushed the support_watch_reactions branch from a28e461 to 9f79887 Compare January 23, 2025 03:17
@AshishNaware
Copy link
Author

Hi @scothis - Sorry for the delay, I was busy with some other high priority tasks. Could you please review this again? I haven't written any tests for above changes. do you have any suggestions on that?
Also, do we need to implement watch function for subResourceClientWrapper and statusWriterWrapper as well? or it will be out of scope for this PR?

Copy link
Member

@scothis scothis left a comment

Choose a reason for hiding this comment

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

It's fine to skip watches for the sub resource clients. Writing tests will be important here since this code won't be exercised in any other way. A good test will show how you expect a Watch/WatchReactor to actually be used.

Comment on lines +346 to +361
err = w.reactWatcherFunc(clientgotesting.NewGetAction(gvr, namespace, name))
if err != nil {
return nil, err
}
err = w.reactWatcherFunc(clientgotesting.NewCreateAction(gvr, namespace, list))
if err != nil {
return nil, err
}
err = w.reactWatcherFunc(clientgotesting.NewDeleteAction(gvr, namespace, name))
if err != nil {
return nil, err
}
err = w.reactWatcherFunc(clientgotesting.NewUpdateAction(gvr, namespace, list))
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

Why are we trying to react to get/create/delete/update here? I would expect it to only react with watch actions. I'm not familiar enough with the mechanics of watch to know exactly what should be here.

@@ -48,9 +48,10 @@ type ReconcilerTestCase struct {

// Request identifies the object to be reconciled
Request reconcilers.Request
// WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
// WithReactors and WithWatchReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
Copy link
Member

Choose a reason for hiding this comment

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

document each field separately, otherwise the info won't show up in tooling for WithWatchReactors.

x3

@@ -69,6 +69,9 @@ type ExpectConfig struct {
// WithReactors installs each ReactionFunc into each fake clientset. ReactionFuncs intercept
// each call to the clientset providing the ability to mutate the resource or inject an error.
WithReactors []ReactionFunc
// WithWatchReactors installs WatchReactionFunc into the fake clientset. This provides ability
// to simulate events in the watcher.
WithWatchReactors []WatchReactionFunc
Copy link
Member

Choose a reason for hiding this comment

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

May also need to define WithWatchReactors for (Sub)ReconcilerTestCase/AdmissionWebhookTestCase and pass it through when creating the ExpectConfig. Then again, I'm not sure watch makes sense in those particular contexts since reconcilers and webhooks are intended to execute at a moment in time while watches are long lived observations of change. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants