fix addAnnotationWithClusterName crash

Signed-off-by: yingjinhui <yingjinhui@didiglobal.com>
This commit is contained in:
yingjinhui 2023-08-21 23:40:42 +08:00
parent 48a37ab5b1
commit 5763248181
1 changed files with 8 additions and 2 deletions

View File

@ -119,7 +119,7 @@ func (r *SearchREST) getObjectItemsFromClusters(
objGVR, namespace, name, cluster.Name, err) objGVR, namespace, name, cluster.Name, err)
continue continue
} }
items = append(items, addAnnotationWithClusterName([]runtime.Object{resourceObject}, cluster.Name)...) items = append(items, addAnnotationWithClusterName([]runtime.Object{resourceObject.DeepCopyObject()}, cluster.Name)...)
} else { } else {
var resourceObjects []runtime.Object var resourceObjects []runtime.Object
if len(namespace) > 0 { if len(namespace) > 0 {
@ -132,7 +132,13 @@ func (r *SearchREST) getObjectItemsFromClusters(
objGVR, cluster.Name, err) objGVR, cluster.Name, err)
continue 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)...)
} }
} }