fix(webhook): fix cache error on k8s client pagination.#1059
Open
fix(webhook): fix cache error on k8s client pagination.#1059
Conversation
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: b29490c | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Summary
Fixes the webhook admission error:
Root Cause
safetyNetCountNotTooLargeuses paginated listing (Limit/Continue) with thecontroller-runtime cached client (
Manager.GetClient()). The cache has twoknown issues (kubernetes-sigs/controller-runtime#3044):
Continueis not supported — the cache rejects it with a hard error.Limitis set, the cache silently returns an incomplete listtruncated at the limit, without signaling that the list is incomplete.
This means neither paginated nor unpaginated listing works correctly with the
cached client for counting resources.
Fix
Use
mgr.GetAPIReader()— a direct API server client that supports properpagination — for the List calls in
safetyNetCountNotTooLarge.Changes:
utils/utils.go: AddAPIReader client.Readerfield toSetupWebhookWithManagerConfig.main.go: Passmgr.GetAPIReader()in the webhook config(
GetAPIReader()is already used for watchers).api/v1beta1/disruption_webhook.go:apiReaderpackage-level variable, initialized from config.Listcalls (Limit: 1000+Continueloops)using
apiReaderinstead of the cachedk8sClient.nodes" in the node-level branch.
ctxfrom the admission handler instead ofcontext.Background().initialSafetyNetsandsafetyNetMissingNetworkFilters.safetyNetMissingNetworkFiltersfrom value to pointer receiver.api/v1beta1/disruption_webhook_test.go: SetapiReaderin all testsetups that exercise safety nets. Add 6 new unit tests for
safetyNetCountNotTooLarge.Code Quality Checklist
Testing
unittests orend-to-endtests.unittests orend-to-endtests.Disruptionresource that previously triggered the error.New tests added
6 unit tests for
safetyNetCountNotTooLargecovering:disableCountTooLargebypass