diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go index e1350042fb2..ac193647a48 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go +++ b/staging/src/k8s.io/apiserver/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/staging/src/k8s.io/apiserver/pkg/storage/testing/store_tests.go b/staging/src/k8s.io/apiserver/pkg/storage/testing/store_tests.go index 6610edad14e..b347f4f9237 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/testing/store_tests.go +++ b/staging/src/k8s.io/apiserver/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 }