-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
[WIP] data consistency checker for list requests #124963
base: master
Are you sure you want to change the base?
[WIP] data consistency checker for list requests #124963
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. 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-sigs/prow repository. |
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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-sigs/prow repository. |
/assign @wojtek-t |
// | ||
// if ResourceVersion = "" and ConsistendListFromCache is disabled or RequestWatchProgress isn't supported, | ||
// then the request will be served from the storage. | ||
func wasListRequestServedFromStorage(opts metav1.ListOptions) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied from the cacher.go - it looks like it does what we want expect the case mentioned in the comment and after clarifying rows 1 and 3 from the KEP.
// | ||
// Note that this function will panic when data inconsistency is detected. | ||
// This is intentional because we want to catch it in the CI. | ||
func CheckListAgainstCacheDataConsistencyIfRequested[T runtime.Object](ctx context.Context, identity string, listItemsFn listItemsFunc[T], optionsUsedToReceiveList metav1.ListOptions, receivedList runtime.Object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to find a better home for this function. Depending on where it is defined and whether it will be public, we could consider adding more validation for opts (e.g., checking if it was actually a list request).
@@ -64,7 +115,7 @@ func checkWatchListDataConsistencyIfRequested(ctx context.Context, identity stri | |||
// it is guarded by an environmental variable. | |||
// we cannot manipulate the environmental variable because | |||
// it will affect other tests in this package. | |||
func checkDataConsistency(ctx context.Context, identity string, lastSyncedResourceVersion string, listItemsFn listItemsFunc, retrieveCollectedItemsFn retrieveCollectedItemsFunc) { | |||
func checkDataConsistency[T runtime.Object, U any](ctx context.Context, identity string, lastSyncedResourceVersion string, listItemsFn listItemsFunc[T], retrieveCollectedItemsFn retrieveCollectedItemsFunc[U]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to find a better home for this function. This function is common for checkWatchListDataConsistencyIfRequested
and CheckListAgainstCacheDataConsistencyIfRequested
.
6fe1b36
to
6583cc6
Compare
@@ -461,6 +462,11 @@ func new$.type|publicPlural$(c *$.GroupGoName$$.Version$Client) *$.type|privateP | |||
var listTemplate = ` | |||
// List takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors. | |||
func (c *$.type|privatePlural$) List(ctx context.Context, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) { | |||
defer func() { | |||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really what you want? We rather want to call it if error was non-nil, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups, yeah, it should have been if err == nil
- thanks.
@@ -697,7 +697,7 @@ func (r *Reflector) watchList(stopCh <-chan struct{}) (watch.Interface, error) { | |||
// we utilize the temporaryStore to ensure independence from the current store implementation. | |||
// as of today, the store is implemented as a queue and will be drained by the higher-level | |||
// component as soon as it finishes replacing the content. | |||
checkWatchListConsistencyIfRequested(stopCh, r.name, resourceVersion, r.listerWatcher, temporaryStore) | |||
checkWatchListDataConsistencyIfRequested(wait.ContextForChannel(stopCh), fmt.Sprintf("watch-list reflector with name: %q", r.name), resourceVersion, wrapListFuncWithContext(r.listerWatcher.List), temporaryStore.List) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, seeing how you want to use it now and where are the problems, let's first merge this commit as a #124446
} | ||
` | ||
|
||
var privateListTemplate = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the reasoning behind this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it allows for passing c.list
to the cache.CheckListAgainstCacheDataConsistencyIfRequested
:
cache.CheckListAgainstCacheDataConsistencyIfRequested(ctx, "list request for examples", c.list, opts, result)
checkDataConsistency(ctx, identity, lastSyncedResourceVersion, listItemsFn, func() []runtime.Object { return rawListItems }) | ||
} | ||
|
||
// wasListRequestServedFromStorage based on the passed ListOptions determines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rather evolve it to something like:
"if continuation wasn't set, the call LIST with RV= and ResourceVersionMatch=Exact and rest parameters the same"
Seems simpler, potentially makes this check unnecessarily, but it's not a big deal.
6583cc6
to
f7457cb
Compare
/retest |
f7457cb
to
57c4f77
Compare
@@ -172,6 +172,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i | |||
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}), | |||
"schemeParameterCodec": c.Universe.Variable(types.Name{Package: path.Join(g.clientsetPackage, "scheme"), Name: "ParameterCodec"}), | |||
"jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}), | |||
"CheckListFromCacheDataConsistencyIfRequested": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/consistencydetector", Name: "CheckListFromCacheDataConsistencyIfRequested"}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's merge the first two commits together
/test pull-kubernetes-node-e2e-containerd |
57c4f77
to
472043e
Compare
472043e
to
42da3cf
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: p0lyn0mial The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@p0lyn0mial: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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-sigs/prow repository. I understand the commands that are listed here. |
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: