mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-31 08:36:16 +00:00
Fix inconsistency in returning list results both in etcd3 and watchcache
This commit is contained in:
@@ -715,6 +715,10 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
|
||||
listVal.Set(reflect.Append(listVal, reflect.ValueOf(elem.Object).Elem()))
|
||||
}
|
||||
}
|
||||
if listVal.IsNil() {
|
||||
// Ensure that we never return a nil Items pointer in the result for consistency.
|
||||
listVal.Set(reflect.MakeSlice(listVal.Type(), 0, 0))
|
||||
}
|
||||
span.AddEvent("Filtered items", attribute.Int("count", listVal.Len()))
|
||||
if c.versioner != nil {
|
||||
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", nil); err != nil {
|
||||
|
@@ -782,6 +782,10 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
|
||||
options = append(options, clientv3.WithRev(withRev))
|
||||
}
|
||||
}
|
||||
if v.IsNil() {
|
||||
// Ensure that we never return a nil Items pointer in the result for consistency.
|
||||
v.Set(reflect.MakeSlice(v.Type(), 0, 0))
|
||||
}
|
||||
|
||||
// instruct the client to begin querying from immediately after the last key we returned
|
||||
// we never return a key that the client wouldn't be allowed to see
|
||||
|
@@ -1088,13 +1088,13 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
|
||||
name: "existing key, resourceVersion=0",
|
||||
key: key,
|
||||
pred: storage.Everything,
|
||||
expectedAlternatives: [][]example.Pod{nil, {*storedObj}},
|
||||
expectedAlternatives: [][]example.Pod{{}, {*storedObj}},
|
||||
rv: "0",
|
||||
}, {
|
||||
name: "existing key, resourceVersion=0, resourceVersionMatch=notOlderThan",
|
||||
key: key,
|
||||
pred: storage.Everything,
|
||||
expectedAlternatives: [][]example.Pod{nil, {*storedObj}},
|
||||
expectedAlternatives: [][]example.Pod{{}, {*storedObj}},
|
||||
rv: "0",
|
||||
rvMatch: metav1.ResourceVersionMatchNotOlderThan,
|
||||
}, {
|
||||
@@ -1142,7 +1142,7 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
|
||||
name: "non-existing key",
|
||||
key: "/non-existing",
|
||||
pred: storage.Everything,
|
||||
expectedOut: nil,
|
||||
expectedOut: []example.Pod{},
|
||||
}, {
|
||||
name: "with matching pod name",
|
||||
key: "/non-existing",
|
||||
@@ -1154,7 +1154,7 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
|
||||
return nil, fields.Set{"metadata.name": pod.Name}, nil
|
||||
},
|
||||
},
|
||||
expectedOut: nil,
|
||||
expectedOut: []example.Pod{},
|
||||
}}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
Reference in New Issue
Block a user