fixing large resourceversion and limit for storages

Kubernetes-commit: ccdef28acd3a286e8d62222ddf804ae4042764e5
This commit is contained in:
PatrickLaabs 2025-06-18 16:22:13 +02:00 committed by Kubernetes Publisher
parent 942549e2f9
commit fdccb8b2dc
2 changed files with 12 additions and 3 deletions

View File

@ -19,6 +19,7 @@ package etcd3
import (
"bytes"
"context"
"errors"
"fmt"
"path"
"reflect"
@ -31,6 +32,7 @@ import (
"go.etcd.io/etcd/client/v3/kubernetes"
"go.opentelemetry.io/otel/attribute"
etcdrpc "go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@ -733,6 +735,14 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
})
metrics.RecordEtcdRequest(metricsOp, s.groupResource, err, startTime)
if err != nil {
if errors.Is(err, etcdrpc.ErrFutureRev) {
currentRV, getRVErr := s.GetCurrentResourceVersion(ctx)
if getRVErr != nil {
// If we can't get the current RV, use 0 as a fallback.
currentRV = 0
}
return storage.NewTooLargeResourceVersionError(uint64(withRev), currentRV, 0)
}
return interpretListError(err, len(opts.Predicate.Continue) > 0, continueKey, keyPrefix)
}
numFetched += len(getResp.Kvs)

View File

@ -1608,9 +1608,8 @@ func RunTestList(ctx context.Context, t *testing.T, store storage.Interface, inc
listCtx := context.WithValue(ctx, recorderContextKey, recorderKey)
err := store.GetList(listCtx, tt.prefix, storageOpts, out)
if tt.expectRVTooLarge {
// TODO: Clasify etcd future revision error as TooLargeResourceVersion
if err == nil || !(storage.IsTooLargeResourceVersion(err) || strings.Contains(err.Error(), "etcdserver: mvcc: required revision is a future revision")) {
t.Fatalf("expecting resource version too high error, but get: %q", err)
if !storage.IsTooLargeResourceVersion(err) {
t.Fatalf("expecting resource version too high error, but get: %v", err)
}
return
}