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

Don't use Continue option with cached client #4458

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

gjkim42
Copy link
Contributor

@gjkim42 gjkim42 commented Aug 7, 2023

What this PR does / why we need it:

This PR makes cache-backed clients not use Continue option to support more than 100 httpRoutes, as the option is not implemented in CacheClient. (It never returns Continue token.)

Which issue this PR fixes:

fixes #4456

Special notes for your reviewer:

PR Readiness Checklist:

Complete these before marking the PR as ready to review:

  • the CHANGELOG.md release notes have been updated to reflect any significant (and particularly user-facing) changes introduced by this PR

@gjkim42 gjkim42 requested a review from a team as a code owner August 7, 2023 08:20
@CLAassistant
Copy link

CLAassistant commented Aug 7, 2023

CLA assistant check
All committers have signed the CLA.

@gjkim42 gjkim42 force-pushed the do-not-use-pagination-in-cached-client branch from 96fb2b6 to 5baf32f Compare August 7, 2023 08:32
@pmalek
Copy link
Member

pmalek commented Aug 7, 2023

Hi @gjkim42 👋

Do you have any links to references that would back this up 🤔?

If that's indeed broken (i.e. the paging is not working with manager's Client) we'd ideally prefer to see a test for this ( to verify the breakage itself and the fix ).

We perform very similar list at

var endpointsList discoveryv1.EndpointSliceList
if err := kubeClient.List(ctx, &endpointsList, &client.ListOptions{
LabelSelector: labelSelector,
Namespace: service.Namespace,
Continue: continueToken,
Limit: defaultEndpointSliceListPagingLimit,
}); err != nil {
return nil, err
}
for _, es := range endpointsList.Items {
adminAPI, err := d.AdminAPIsFromEndpointSlice(es)
if err != nil {
return nil, err
}
addresses = addresses.Union(adminAPI)
}
if endpointsList.Continue == "" {
break
}
continueToken = endpointsList.Continue
but that's done with client.New() at
return client.New(conf, client.Options{})
and not the manager's client that's created by the https://pkg.go.dev/sigs.k8s.io/controller-runtime#NewManager at
mgr, err := ctrl.NewManager(kubeconfig, controllerOpts)
🤔

@czeslavo
Copy link
Contributor

czeslavo commented Aug 7, 2023

I think that's more of a bug in the upstream. We're using client.Reader / client.Client interface here and I would expect every implementation (cached or not cached) to be compliant with the possible options it accepts in its List method. I wrote about it under the upstream issue: kubernetes-sigs/controller-runtime#2439

To not block ourselves with the upstream process of fixing that, I'm ok with the workaround implemented in this PR, but as it was mentioned, it'd be great to have this covered in an envtest before merging.

@gjkim42
Copy link
Contributor Author

gjkim42 commented Aug 8, 2023

Do you have any links to references that would back this up 🤔?

I've investigated the code here, the CacheReader never sets the Continue token in its output.

We are having a PR related to this issue in the upstream repository here recently.

We perform very similar list at

var endpointsList discoveryv1.EndpointSliceList
if err := kubeClient.List(ctx, &endpointsList, &client.ListOptions{
LabelSelector: labelSelector,
Namespace: service.Namespace,
Continue: continueToken,
Limit: defaultEndpointSliceListPagingLimit,
}); err != nil {
return nil, err
}
for _, es := range endpointsList.Items {
adminAPI, err := d.AdminAPIsFromEndpointSlice(es)
if err != nil {
return nil, err
}
addresses = addresses.Union(adminAPI)
}
if endpointsList.Continue == "" {
break
}
continueToken = endpointsList.Continue

but that's done with client.New() at

Unlike this patch, I think that the code may work fine, as it is, if the client is not CacheReader.


it'd be great to have this covered in an envtest before merging.

I'll add one.

@pull-request-size pull-request-size bot added size/L and removed size/S labels Aug 8, 2023
@gjkim42 gjkim42 force-pushed the do-not-use-pagination-in-cached-client branch from 93dad3a to 72244cf Compare August 8, 2023 09:53
@gjkim42
Copy link
Contributor Author

gjkim42 commented Aug 8, 2023

  • added TestHTTPRouteGetAttachedRoutesMoreThan100 integration test
  • updated CHANGELOG.md

/cc @pmalek @czeslavo
Could you PTAL?

CHANGELOG.md Outdated Show resolved Hide resolved
test/integration/httproute_test.go Outdated Show resolved Hide resolved
@gjkim42 gjkim42 force-pushed the do-not-use-pagination-in-cached-client branch from 72244cf to 1a94301 Compare August 8, 2023 12:48
@czeslavo czeslavo enabled auto-merge (squash) August 8, 2023 14:49
@czeslavo czeslavo added the fix label Aug 8, 2023
@czeslavo czeslavo added this to the KIC v2.11.0 milestone Aug 8, 2023
@czeslavo czeslavo merged commit ef7936f into Kong:main Aug 8, 2023
22 checks passed
@gjkim42 gjkim42 deleted the do-not-use-pagination-in-cached-client branch August 8, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Having more than 100 httproutes may causes excessive resource conflicts
4 participants