From 5c78ed890c50b4b4167fd079f7dd5777177e9e08 Mon Sep 17 00:00:00 2001 From: Bruce Ma Date: Tue, 29 Mar 2022 20:57:31 +0800 Subject: [PATCH] returned objects of reference type should be unchangeable Signed-off-by: Bruce Ma --- pkg/cache/informer_cache.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cache/informer_cache.go b/pkg/cache/informer_cache.go index c5a25ca179..ac07be2a6e 100644 --- a/pkg/cache/informer_cache.go +++ b/pkg/cache/informer_cache.go @@ -193,8 +193,8 @@ func indexByField(indexer Informer, field string, extractor client.IndexerFunc) rawVals := extractor(obj) var vals []string if ns == "" { - // if we're not doubling the keys for the namespaced case, just re-use what was returned to us - vals = rawVals + // if we're not doubling the keys for the namespaced case, just create a new slice with same length + vals = make([]string, len(rawVals)) } else { // if we need to add non-namespaced versions too, double the length vals = make([]string, len(rawVals)*2)