fixed infinite loop in watchControllerOf API
This changes fixes a bug where generic controller
can get stuck in inifite loop while resolving parent object
for a generated object. It can happen where we encounter
an object with no owner reference while walking up the ancestor tree
and lookup paths are not yet done.
@@ -127,7 +127,11 @@ func (m MapToController) Map(obj interface{}) string {
o := object
for len(m.Path) > 0 {
// Get the owner reference
- if ownerRef := metav1.GetControllerOf(o); ownerRef != nil {
+ ownerRef := metav1.GetControllerOf(o)
+ if ownerRef == nil {
+ glog.V(2).Infof("object %v does not have any owner reference", o)
+ return ""
+ }
// Resolve the owner object and check if the UID of the looked up object matches the reference.
owner, err := m.Path[0](types.ReconcileKey{Name: ownerRef.Name, Namespace: o.GetNamespace()})
if err != nil || owner == nil {
@@ -151,7 +155,6 @@ func (m MapToController) Map(obj interface{}) string {
return object.GetNamespace() + "/" + ownerRef.Name
}
}
- }
return ""
}
