Skip to content

Commit

Permalink
Copy object before modifying it
Browse files Browse the repository at this point in the history
Otherwise you can get races when getting and listing simultaneously
  • Loading branch information
JoelSpeed committed Apr 3, 2019
1 parent bab2dad commit 7f16f2b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/cache/internal/cache_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ func (c *CacheReader) List(_ context.Context, out runtime.Object, opts ...client
if !isObj {
return fmt.Errorf("cache contained %T, which is not an Object", obj)
}
obj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
runtimeObjs = append(runtimeObjs, obj)
outObj := obj.DeepCopyObject()
outObj.GetObjectKind().SetGroupVersionKind(c.groupVersionKind)
runtimeObjs = append(runtimeObjs, outObj)
}
filteredItems, err := objectutil.FilterWithLabels(runtimeObjs, labelSel)
if err != nil {
Expand Down

0 comments on commit 7f16f2b

Please sign in to comment.