From fdccb8b2dc7b229ce26dc7e0e565577c455f8274 Mon Sep 17 00:00:00 2001 From: PatrickLaabs Date: Wed, 18 Jun 2025 16:22:13 +0200 Subject: [PATCH] fixing large resourceversion and limit for storages Kubernetes-commit: ccdef28acd3a286e8d62222ddf804ae4042764e5 --- pkg/storage/etcd3/store.go | 10 ++++++++++ pkg/storage/testing/store_tests.go | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/storage/etcd3/store.go b/pkg/storage/etcd3/store.go index e1350042f..ac193647a 100644 --- a/pkg/storage/etcd3/store.go +++ b/pkg/storage/etcd3/store.go @@ -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) diff --git a/pkg/storage/testing/store_tests.go b/pkg/storage/testing/store_tests.go index 6610edad1..b347f4f92 100644 --- a/pkg/storage/testing/store_tests.go +++ b/pkg/storage/testing/store_tests.go @@ -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 }