Skip to content

Commit

Permalink
remove owner passed in to RemoveControlleReference only when that own…
Browse files Browse the repository at this point in the history
…er controller equals true

Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
  • Loading branch information
troy0820 committed Nov 24, 2023
1 parent 2154ffb commit 5f0a3f4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/controller/controllerutil/controllerutil.go
Expand Up @@ -171,7 +171,14 @@ func RemoveControllerReference(owner, object metav1.Object, scheme *runtime.Sche
if ok := HasControllerReference(object); !ok {
return fmt.Errorf("%T does not have a owner reference with controller equals true", object)
}
return RemoveOwnerReference(owner, object, scheme)
ownerRefs := object.GetOwnerReferences()
for _, ownerRef := range ownerRefs {
t := ptr.To(true)
if ownerRef.Controller == t && ownerRef.Name == owner.GetName() {
return RemoveOwnerReference(owner, object, scheme)
}
}
return fmt.Errorf("%T is not owned reference by %T where controller equals true", object, owner)
}

func upsertOwnerRef(ref metav1.OwnerReference, object metav1.Object) {
Expand Down

0 comments on commit 5f0a3f4

Please sign in to comment.