From 809fd64b289add1b378b45c748c23b7278c366f1 Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Fri, 22 Apr 2022 11:50:24 -0700 Subject: [PATCH] storage/etcd3: clarify the pagingation flow in LIST It is not possible for the nil-check to ever return anything different from what the explicit boolean used to, but this is only something that a reader can come to the conclusion on if they very, very carefuly read the code. Instead of having this implicit flow that is difficult to follow, let's keep the boolean. Signed-off-by: Steve Kuznetsov --- staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 75a6c3b58b8..5a287522fc8 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go @@ -593,9 +593,11 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption // set the appropriate clientv3 options to filter the returned data set var limitOption *clientv3.OpOption - var limit int64 = pred.Limit + limit := pred.Limit + var paging bool options := make([]clientv3.OpOption, 0, 4) if s.pagingEnabled && pred.Limit > 0 { + paging = true options = append(options, clientv3.WithLimit(limit)) limitOption = &options[len(options)-1] } @@ -722,7 +724,7 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption // take items from the response until the bucket is full, filtering as we go for i, kv := range getResp.Kvs { - if limitOption != nil && int64(v.Len()) >= pred.Limit { + if paging && int64(v.Len()) >= pred.Limit { hasMore = true break } @@ -748,7 +750,7 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption } // no more results remain or we didn't request paging - if !hasMore || limitOption == nil { + if !hasMore || !paging { break } // we're paging but we have filled our bucket