From 5763248181ed3a90684b36b4d5d2ffea2c68d987 Mon Sep 17 00:00:00 2001 From: yingjinhui Date: Mon, 21 Aug 2023 23:40:42 +0800 Subject: [PATCH] fix addAnnotationWithClusterName crash Signed-off-by: yingjinhui --- pkg/registry/search/storage/cache.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/registry/search/storage/cache.go b/pkg/registry/search/storage/cache.go index c5703293d..1d0864b92 100644 --- a/pkg/registry/search/storage/cache.go +++ b/pkg/registry/search/storage/cache.go @@ -119,7 +119,7 @@ func (r *SearchREST) getObjectItemsFromClusters( objGVR, namespace, name, cluster.Name, err) continue } - items = append(items, addAnnotationWithClusterName([]runtime.Object{resourceObject}, cluster.Name)...) + items = append(items, addAnnotationWithClusterName([]runtime.Object{resourceObject.DeepCopyObject()}, cluster.Name)...) } else { var resourceObjects []runtime.Object if len(namespace) > 0 { @@ -132,7 +132,13 @@ func (r *SearchREST) getObjectItemsFromClusters( objGVR, cluster.Name, err) continue } - items = append(items, addAnnotationWithClusterName(resourceObjects, cluster.Name)...) + + cloneObjects := make([]runtime.Object, len(resourceObjects)) + for i := range resourceObjects { + cloneObjects[i] = resourceObjects[i].DeepCopyObject() + } + + items = append(items, addAnnotationWithClusterName(cloneObjects, cluster.Name)...) } }