Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pooknull committed Feb 11, 2025
1 parent 3a1794f commit c15aaa8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/k8s/setowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

// SetControllerReference sets owner as a owner for the object obj
func SetControllerReference(owner runtime.Object, obj metav1.Object, scheme *runtime.Scheme) error {
ownerRef, err := OwnerRef(owner, scheme)
if err != nil {
return err
}
obj.SetOwnerReferences(append(obj.GetOwnerReferences(), ownerRef))
return nil
}

// OwnerRef returns OwnerReference to object
func OwnerRef(ro runtime.Object, scheme *runtime.Scheme) (metav1.OwnerReference, error) {
gvk, err := apiutil.GVKForObject(ro, scheme)
Expand Down

0 comments on commit c15aaa8

Please sign in to comment.