func AddOwnerReference(o metav1.Object, r metav1.OwnerReference) {
	refs := o.GetOwnerReferences()
	for i := range refs {
		if refs[i].UID == r.UID {
			refs[i] = r
			o.SetOwnerReferences(refs)
			return
		}
	}
	o.SetOwnerReferences(append(refs, r))
}
AddOwnerReference to the supplied object' metadata. Any existing owner with
the same UID as the supplied reference will be replaced.
package meta
import (
	"fmt"
	"hash/fnv"
	"strings"
	"time"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"k8s.io/apimachinery/pkg/types"
	xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
	"github.com/crossplane/crossplane-runtime/pkg/errors"
)
const (
	AnnotationKeyExternalName = "crossplane.io/external-name"
	AnnotationKeyExternalCreatePending = "crossplane.io/external-create-pending"
	AnnotationKeyExternalCreateSucceeded = "crossplane.io/external-create-succeeded"
	AnnotationKeyExternalCreateFailed = "crossplane.io/external-create-failed"
)
const (
	AnnotationKeyPropagateToPrefix = "to.propagate.crossplane.io/"
	AnnotationKeyPropagateFromNamespace = "from.propagate.crossplane.io/namespace"
	AnnotationKeyPropagateFromName      = "from.propagate.crossplane.io/name"
)
func ReferenceTo(o metav1.Object, of schema.GroupVersionKind) *corev1.ObjectReference {
	v, k := of.ToAPIVersionAndKind()
	return &corev1.ObjectReference{
		APIVersion: v,
		Kind:       k,
		Namespace:  o.GetNamespace(),
		Name:       o.GetName(),
		UID:        o.GetUID(),
	}
}
func TypedReferenceTo(o metav1.Object, of schema.GroupVersionKind) *xpv1.TypedReference {
	v, k := of.ToAPIVersionAndKind()
	return &xpv1.TypedReference{
		APIVersion: v,
		Kind:       k,
		Name:       o.GetName(),
		UID:        o.GetUID(),
	}
}
func AsOwner(r *xpv1.TypedReference) metav1.OwnerReference {
	return metav1.OwnerReference{
		APIVersion: r.APIVersion,
		Kind:       r.Kind,
		Name:       r.Name,
		UID:        r.UID,
	}
}
func AsController(r *xpv1.TypedReference) metav1.OwnerReference {
	c := true
	ref := AsOwner(r)
	ref.Controller = &c
	return ref
}
func HaveSameController(a, b metav1.Object) bool {
	ac := metav1.GetControllerOf(a)
	bc := metav1.GetControllerOf(b)
	if ac == nil || bc == nil {
		return false
	}
	return ac.UID == bc.UID
}
func NamespacedNameOf(r *corev1.ObjectReference) types.NamespacedName {
	return types.NamespacedName{Namespace: r.Namespace, Name: r.Name}
}