Migrate to GetControllerOf from meta/v1 package

This commit is contained in:
Mikhail Mazurskiy
2017-08-02 19:41:33 +10:00
parent 5490273951
commit b28a83a4cf
30 changed files with 77 additions and 109 deletions

View File

@@ -31,19 +31,6 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
// GetControllerOf returns the controllerRef if controllee has a controller,
// otherwise returns nil.
func GetControllerOf(controllee metav1.Object) *metav1.OwnerReference {
ownerRefs := controllee.GetOwnerReferences()
for i := range ownerRefs {
owner := &ownerRefs[i]
if owner.Controller != nil && *owner.Controller == true {
return owner
}
}
return nil
}
type BaseControllerRefManager struct {
Controller metav1.Object
Selector labels.Selector
@@ -78,7 +65,7 @@ func (m *BaseControllerRefManager) CanAdopt() error {
//
// No reconciliation will be attempted if the controller is being deleted.
func (m *BaseControllerRefManager) ClaimObject(obj metav1.Object, match func(metav1.Object) bool, adopt, release func(metav1.Object) error) (bool, error) {
controllerRef := GetControllerOf(obj)
controllerRef := metav1.GetControllerOf(obj)
if controllerRef != nil {
if controllerRef.UID != m.Controller.GetUID() {
// Owned by someone else. Ignore.