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

✨ Cache-Backed Client: Support listOpts.Limit #1479

Merged
merged 3 commits into from
May 3, 2021
Merged

✨ Cache-Backed Client: Support listOpts.Limit #1479

merged 3 commits into from
May 3, 2021

Conversation

MadhavJivrajani
Copy link
Contributor

Enabled list options in List implementation of Reader by the infromer cache in order to respect client.Limit if set.

Fix #1422

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 16, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @MadhavJivrajani. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 16, 2021
@alvaroaleman
Copy link
Member

@MadhavJivrajani can you please add a test for the Limit option?

@MadhavJivrajani
Copy link
Contributor Author

Oh woops, sorry about that. I'll add it :)

Thanks!

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 19, 2021
@MadhavJivrajani
Copy link
Contributor Author

@alvaroaleman I've added the test, could you PTAL?

@MadhavJivrajani
Copy link
Contributor Author

@alvaroaleman could you PTAL?

@alvaroaleman
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 26, 2021
- add test for informer cache limit option

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
@MadhavJivrajani
Copy link
Contributor Author

MadhavJivrajani commented Apr 26, 2021

Hey @alvaroaleman, the Limit option doesn't seem to be implemented for multi-namespace cached either, would it be okay to have a Limit option there as well? And if so is it okay if I try and implement it as part of this PR or should I open another issue for the same?

@alvaroaleman
Copy link
Member

Hey @alvaroaleman, the Limit option doesn't seem to be implemented for multi-namespace cached either, would it be okay to have a Limit option there as well? And if so is it okay if I try and implement it as part of this PR or should I open another issue for the same?

It would be good to support it everywhere at once, if that isn't too much work.

@MadhavJivrajani
Copy link
Contributor Author

Sure, no worries. 😄

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 27, 2021
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 30, 2021
@MadhavJivrajani
Copy link
Contributor Author

Hey @alvaroaleman, could you PTAL?

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

@MadhavJivrajani thanks, sorry, this fell of my radar. The MultiNamespaceCache implementation is incorrect and just passes the tests by coincidence, because we only have one pod per namespace in the test scenario.

If you do something like this it instantly starts failing:

diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go
index 9a41662a..6f0cdd39 100644
--- a/pkg/cache/cache_test.go
+++ b/pkg/cache/cache_test.go
@@ -100,6 +100,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
                        knownPod2           client.Object
                        knownPod3           client.Object
                        knownPod4           client.Object
+                       knownPod99          client.Object
                )
 
                BeforeEach(func() {
@@ -119,6 +120,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
                        Expect(err).NotTo(HaveOccurred())
                        // Includes restart policy since these objects are indexed on this field.
                        knownPod1 = createPod("test-pod-1", testNamespaceOne, kcorev1.RestartPolicyNever)
+                       knownPod99 = createPod("test-pod-99", testNamespaceOne, kcorev1.RestartPolicyNever)
                        knownPod2 = createPod("test-pod-2", testNamespaceTwo, kcorev1.RestartPolicyAlways)
                        knownPod3 = createPodWithLabels("test-pod-3", testNamespaceTwo, kcorev1.RestartPolicyOnFailure, map[string]string{"common-label": "common"})
                        knownPod4 = createPodWithLabels("test-pod-4", testNamespaceThree, kcorev1.RestartPolicyNever, map[string]string{"common-label": "common"})
@@ -149,6 +151,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
                        deletePod(knownPod2)
                        deletePod(knownPod3)
                        deletePod(knownPod4)
+                       deletePod(knownPod99)
 
                        informerCacheCancel()
                })
@@ -295,7 +298,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
                                        Expect(errors.IsTimeout(err)).To(BeTrue())
                                })
 
-                               It("should set the Limit option and limit number of objects to Limit when List is called", func() {
+                               FIt("should set the Limit option and limit number of objects to Limit when List is called", func() {
                                        By("setting the Limit option to 1")
                                        opts := &client.ListOptions{Limit: int64(1)}
                                        limitListOpts := &client.ListOptions{}

I am fine with both leaving it for a follow-up (but then, please disable the test for the multi-namespace cache) or fixing it here (I think it actually shouldn't be too hard).

If you fix it, please also change the tests to actually have a namespace with more than one object :)

pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
@MadhavJivrajani
Copy link
Contributor Author

If you fix it, please also change the tests to actually have a namespace with more than one object :)

Will do 👍🏻

@MadhavJivrajani
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 1, 2021
@MadhavJivrajani
Copy link
Contributor Author

@alvaroaleman any idea as to why it says:

testing: warning: no tests to run

For some reason, both ${MOD_OPT} and ${WHAT} in hack/test-all.sh seem to be empty?

@MadhavJivrajani
Copy link
Contributor Author

/remove-hold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 1, 2021
@alvaroaleman
Copy link
Member

For some reason, both ${MOD_OPT} and ${WHAT} in hack/test-all.sh seem to be empty?

Lol, thanks for noticing. It seems we don't run any unittests in CI currently. I've opened #1503 for that (And we will not merge anything until that one is in).

pkg/cache/multi_namespace_cache.go Outdated Show resolved Hide resolved
pkg/cache/multi_namespace_cache.go Show resolved Hide resolved
pkg/cache/cache_test.go Outdated Show resolved Hide resolved
@MadhavJivrajani
Copy link
Contributor Author

/test pull-controller-runtime-test-master

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
@alvaroaleman alvaroaleman changed the title ✨ Enable list opts in informer cache List ✨ Support listOpts.Limit in informer cache reader May 3, 2021
@alvaroaleman alvaroaleman changed the title ✨ Support listOpts.Limit in informer cache reader ✨ Cache-Backed Client: Support listOpts.Limit May 3, 2021
@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 3, 2021
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 3, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, MadhavJivrajani

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 3, 2021
@k8s-ci-robot k8s-ci-robot merged commit 0c99fc7 into kubernetes-sigs:master May 3, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.9.x milestone May 3, 2021
aayushrangwala pushed a commit to aayushrangwala/controller-runtime that referenced this pull request May 5, 2021
* Enable list opts in informer cache List
- add test for informer cache limit option

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* enable Limit option in multi namespace cache

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

delegatingClient with client.informerCache does not respect client.Limit option
3 participants