فهرست منبع

Revert "reduce memory consumption (#2725)" (#2998) (#2999)

This reverts commit a3beb32763c5e56f7aafbb957724f1cdd8b197f0.

Signed-off-by: Nik Willwerth <nwillwerth@kubecost.com>
Co-authored-by: Cliff Colvin <ccolvin@kubecost.com>
nik-kc 1 سال پیش
والد
کامیت
92da2a5f56
1فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 13 1
      pkg/clustercache/watchcontroller.go

+ 13 - 1
pkg/clustercache/watchcontroller.go

@@ -88,7 +88,19 @@ func NewCachingWatcher(restClient rest.Interface, resource string, resourceType
 }
 
 func (c *CachingWatchController) GetAll() []interface{} {
-	return c.indexer.List()
+	list := c.indexer.List()
+
+	// since the indexer returns the as-is pointer to the resource,
+	// we deep copy the resources such that callers don't corrupt the
+	// index
+	cloneList := make([]interface{}, 0, len(list))
+	for _, v := range list {
+		if deepCopyable, ok := v.(rt.Object); ok {
+			cloneList = append(cloneList, deepCopyable.DeepCopyObject())
+		}
+	}
+
+	return cloneList
 }
 
 func (c *CachingWatchController) SetUpdateHandler(handler WatchHandler) WatchController {