Skip to content

Commit 9248fea

Browse files
committed
Fix RemoveOwnerRef so that it does not mutate its input
1 parent 5e5bfbc commit 9248fea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

util/util.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ func ReplaceOwnerRef(ownerReferences []metav1.OwnerReference, source metav1.Obje
326326
// RemoveOwnerRef returns the slice of owner references after removing the supplied owner ref.
327327
func RemoveOwnerRef(ownerReferences []metav1.OwnerReference, inputRef metav1.OwnerReference) []metav1.OwnerReference {
328328
if index := indexOwnerRef(ownerReferences, inputRef); index != -1 {
329-
return append(ownerReferences[:index], ownerReferences[index+1:]...)
329+
copyOwnerReferences := append([]metav1.OwnerReference{}, ownerReferences...)
330+
return append(copyOwnerReferences[:index], copyOwnerReferences[index+1:]...)
330331
}
331332
return ownerReferences
332333
}

0 commit comments

Comments
 (0)