Make GetRemainingItemCount/SetRemainingItemCount use pointers
Kubernetes-commit: 145e8c46cf81ff16b65ff729c392ced262984847
This commit is contained in:
parent
74be843d4b
commit
00e2435130
|
@ -67,7 +67,7 @@ func (c defaultTableConvertor) ConvertToTable(ctx context.Context, object runtim
|
|||
table.ResourceVersion = m.GetResourceVersion()
|
||||
table.SelfLink = m.GetSelfLink()
|
||||
table.Continue = m.GetContinue()
|
||||
table.SetRemainingItemCount(m.GetRemainingItemCount())
|
||||
table.RemainingItemCount = m.GetRemainingItemCount()
|
||||
} else {
|
||||
if m, err := meta.CommonAccessor(object); err == nil {
|
||||
table.ResourceVersion = m.GetResourceVersion()
|
||||
|
|
|
@ -605,7 +605,7 @@ func (c *Cacher) GetToList(ctx context.Context, key string, resourceVersion stri
|
|||
}
|
||||
}
|
||||
if c.versioner != nil {
|
||||
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", 0); err != nil {
|
||||
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, p
|
|||
}
|
||||
trace.Step(fmt.Sprintf("Filtered %d items", listVal.Len()))
|
||||
if c.versioner != nil {
|
||||
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", 0); err != nil {
|
||||
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ type testVersioner struct{}
|
|||
func (testVersioner) UpdateObject(obj runtime.Object, resourceVersion uint64) error {
|
||||
return meta.NewAccessor().SetResourceVersion(obj, strconv.FormatUint(resourceVersion, 10))
|
||||
}
|
||||
func (testVersioner) UpdateList(obj runtime.Object, resourceVersion uint64, continueValue string, count int64) error {
|
||||
func (testVersioner) UpdateList(obj runtime.Object, resourceVersion uint64, continueValue string, count *int64) error {
|
||||
listAccessor, err := meta.ListAccessor(obj)
|
||||
if err != nil || listAccessor == nil {
|
||||
return err
|
||||
|
|
|
@ -44,7 +44,7 @@ func (a APIObjectVersioner) UpdateObject(obj runtime.Object, resourceVersion uin
|
|||
}
|
||||
|
||||
// UpdateList implements Versioner
|
||||
func (a APIObjectVersioner) UpdateList(obj runtime.Object, resourceVersion uint64, nextKey string, count int64) error {
|
||||
func (a APIObjectVersioner) UpdateList(obj runtime.Object, resourceVersion uint64, nextKey string, count *int64) error {
|
||||
listAccessor, err := meta.ListAccessor(obj)
|
||||
if err != nil || listAccessor == nil {
|
||||
return err
|
||||
|
|
|
@ -391,7 +391,7 @@ func (s *store) GetToList(ctx context.Context, key string, resourceVersion strin
|
|||
}
|
||||
}
|
||||
// update version with cluster level revision
|
||||
return s.versioner.UpdateList(listObj, uint64(getResp.Header.Revision), "", 0)
|
||||
return s.versioner.UpdateList(listObj, uint64(getResp.Header.Revision), "", nil)
|
||||
}
|
||||
|
||||
func (s *store) Count(key string) (int64, error) {
|
||||
|
@ -618,17 +618,19 @@ func (s *store) List(ctx context.Context, key, resourceVersion string, pred stor
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
remainingItemCount := getResp.Count - pred.Limit
|
||||
var remainingItemCount *int64
|
||||
// getResp.Count counts in objects that do not match the pred.
|
||||
// Instead of returning inaccurate count, return 0.
|
||||
if !pred.Empty() {
|
||||
remainingItemCount = 0
|
||||
// Instead of returning inaccurate count for non-empty selectors, we return nil.
|
||||
// Only set remainingItemCount if the predicate is empty.
|
||||
if pred.Empty() {
|
||||
c := int64(getResp.Count - pred.Limit)
|
||||
remainingItemCount = &c
|
||||
}
|
||||
return s.versioner.UpdateList(listObj, uint64(returnedRV), next, remainingItemCount)
|
||||
}
|
||||
|
||||
// no continuation
|
||||
return s.versioner.UpdateList(listObj, uint64(returnedRV), "", 0)
|
||||
return s.versioner.UpdateList(listObj, uint64(returnedRV), "", nil)
|
||||
}
|
||||
|
||||
// growSlice takes a slice value and grows its capacity up
|
||||
|
|
|
@ -47,6 +47,7 @@ import (
|
|||
"k8s.io/apiserver/pkg/storage/etcd"
|
||||
storagetests "k8s.io/apiserver/pkg/storage/tests"
|
||||
"k8s.io/apiserver/pkg/storage/value"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
var scheme = runtime.NewScheme()
|
||||
|
@ -831,7 +832,7 @@ func TestList(t *testing.T) {
|
|||
pred storage.SelectionPredicate
|
||||
expectedOut []*example.Pod
|
||||
expectContinue bool
|
||||
expectedRemainingItemCount int64
|
||||
expectedRemainingItemCount *int64
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
|
@ -884,7 +885,7 @@ func TestList(t *testing.T) {
|
|||
},
|
||||
expectedOut: []*example.Pod{preset[1].storedObj},
|
||||
expectContinue: true,
|
||||
expectedRemainingItemCount: 1,
|
||||
expectedRemainingItemCount: utilpointer.Int64Ptr(1),
|
||||
},
|
||||
{
|
||||
name: "test List with limit when paging disabled",
|
||||
|
@ -1062,8 +1063,8 @@ func TestList(t *testing.T) {
|
|||
t.Errorf("(%s): length of list want=%d, got=%d", tt.name, len(tt.expectedOut), len(out.Items))
|
||||
continue
|
||||
}
|
||||
if e, a := tt.expectedRemainingItemCount, out.ListMeta.GetRemainingItemCount(); e != a {
|
||||
t.Errorf("(%s): remainingItemCount want=%d, got=%d", tt.name, e, a)
|
||||
if e, a := tt.expectedRemainingItemCount, out.ListMeta.GetRemainingItemCount(); (e == nil) != (a == nil) || (e != nil && a != nil && *e != *a) {
|
||||
t.Errorf("(%s): remainingItemCount want=%#v, got=%#v", tt.name, e, a)
|
||||
}
|
||||
for j, wantPod := range tt.expectedOut {
|
||||
getPod := &out.Items[j]
|
||||
|
|
|
@ -44,8 +44,8 @@ type Versioner interface {
|
|||
// database. continueValue is optional and indicates that more results are available if the client
|
||||
// passes that value to the server in a subsequent call. remainingItemCount indicates the number
|
||||
// of remaining objects if the list is partial. The remainingItemCount field is omitted during
|
||||
// serialization if it is set to 0.
|
||||
UpdateList(obj runtime.Object, resourceVersion uint64, continueValue string, remainingItemCount int64) error
|
||||
// serialization if it is set to nil.
|
||||
UpdateList(obj runtime.Object, resourceVersion uint64, continueValue string, remainingItemCount *int64) error
|
||||
// PrepareObjectForStorage should set SelfLink and ResourceVersion to the empty value. Should
|
||||
// return an error if the specified object cannot be updated.
|
||||
PrepareObjectForStorage(obj runtime.Object) error
|
||||
|
|
Loading…
Reference in New Issue