mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-03 10:17:46 +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()))
|
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()))
|
span.AddEvent("Filtered items", attribute.Int("count", listVal.Len()))
|
||||||
if c.versioner != nil {
|
if c.versioner != nil {
|
||||||
if err := c.versioner.UpdateList(listObj, readResourceVersion, "", nil); err != 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))
|
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
|
// 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
|
// 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",
|
name: "existing key, resourceVersion=0",
|
||||||
key: key,
|
key: key,
|
||||||
pred: storage.Everything,
|
pred: storage.Everything,
|
||||||
expectedAlternatives: [][]example.Pod{nil, {*storedObj}},
|
expectedAlternatives: [][]example.Pod{{}, {*storedObj}},
|
||||||
rv: "0",
|
rv: "0",
|
||||||
}, {
|
}, {
|
||||||
name: "existing key, resourceVersion=0, resourceVersionMatch=notOlderThan",
|
name: "existing key, resourceVersion=0, resourceVersionMatch=notOlderThan",
|
||||||
key: key,
|
key: key,
|
||||||
pred: storage.Everything,
|
pred: storage.Everything,
|
||||||
expectedAlternatives: [][]example.Pod{nil, {*storedObj}},
|
expectedAlternatives: [][]example.Pod{{}, {*storedObj}},
|
||||||
rv: "0",
|
rv: "0",
|
||||||
rvMatch: metav1.ResourceVersionMatchNotOlderThan,
|
rvMatch: metav1.ResourceVersionMatchNotOlderThan,
|
||||||
}, {
|
}, {
|
||||||
@@ -1142,7 +1142,7 @@ func RunTestGetListNonRecursive(ctx context.Context, t *testing.T, store storage
|
|||||||
name: "non-existing key",
|
name: "non-existing key",
|
||||||
key: "/non-existing",
|
key: "/non-existing",
|
||||||
pred: storage.Everything,
|
pred: storage.Everything,
|
||||||
expectedOut: nil,
|
expectedOut: []example.Pod{},
|
||||||
}, {
|
}, {
|
||||||
name: "with matching pod name",
|
name: "with matching pod name",
|
||||||
key: "/non-existing",
|
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
|
return nil, fields.Set{"metadata.name": pod.Name}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedOut: nil,
|
expectedOut: []example.Pod{},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
Reference in New Issue
Block a user