diff --git a/pkg/controller/daemon/daemon_controller.go b/pkg/controller/daemon/daemon_controller.go index d98087d3e1..ce2d90ef41 100644 --- a/pkg/controller/daemon/daemon_controller.go +++ b/pkg/controller/daemon/daemon_controller.go @@ -1068,7 +1068,7 @@ func (dsc *DaemonSetsController) simulate(newPod *v1.Pod, node *v1.Node, ds *ext } // ignore pods that belong to the daemonset when taking into account whether // a daemonset should bind to a node. - if controllerRef := metav1.GetControllerOf(pod); controllerRef != nil && controllerRef.UID == ds.UID { + if metav1.IsControlledBy(pod, ds) { continue } pods = append(pods, pod) diff --git a/pkg/controller/deployment/util/deployment_util.go b/pkg/controller/deployment/util/deployment_util.go index caa108b820..45419f48dd 100644 --- a/pkg/controller/deployment/util/deployment_util.go +++ b/pkg/controller/deployment/util/deployment_util.go @@ -579,8 +579,7 @@ func ListReplicaSets(deployment *extensions.Deployment, getRSList RsListFunc) ([ // Only include those whose ControllerRef matches the Deployment. owned := make([]*extensions.ReplicaSet, 0, len(all)) for _, rs := range all { - controllerRef := metav1.GetControllerOf(rs) - if controllerRef != nil && controllerRef.UID == deployment.UID { + if metav1.IsControlledBy(rs, deployment) { owned = append(owned, rs) } } @@ -603,8 +602,7 @@ func ListReplicaSetsInternal(deployment *internalextensions.Deployment, getRSLis // Only include those whose ControllerRef matches the Deployment. filtered := make([]*internalextensions.ReplicaSet, 0, len(all)) for _, rs := range all { - controllerRef := metav1.GetControllerOf(rs) - if controllerRef != nil && controllerRef.UID == deployment.UID { + if metav1.IsControlledBy(rs, deployment) { filtered = append(filtered, rs) } } diff --git a/pkg/controller/history/controller_history_test.go b/pkg/controller/history/controller_history_test.go index 296fb761dc..ab5845eb34 100644 --- a/pkg/controller/history/controller_history_test.go +++ b/pkg/controller/history/controller_history_test.go @@ -992,7 +992,7 @@ func TestRealHistory_AdoptControllerRevision(t *testing.T) { if !test.err && err != nil { t.Errorf("%s: %s", test.name, err) } - if !test.err && metav1.GetControllerOf(adopted).UID != test.parent.GetUID() { + if !test.err && !metav1.IsControlledBy(adopted, test.parent) { t.Errorf("%s: adoption failed", test.name) } if test.err && err == nil { @@ -1103,7 +1103,7 @@ func TestFakeHistory_AdoptControllerRevision(t *testing.T) { if !test.err && err != nil { t.Errorf("%s: %s", test.name, err) } - if !test.err && metav1.GetControllerOf(adopted).UID != test.parent.GetUID() { + if !test.err && !metav1.IsControlledBy(adopted, test.parent) { t.Errorf("%s: adoption failed", test.name) } if test.err && err == nil { @@ -1211,8 +1211,7 @@ func TestRealHistory_ReleaseControllerRevision(t *testing.T) { if found == nil { return true, nil, errors.NewNotFound(apps.Resource("controllerrevisions"), test.revision.Name) } - if foundParent := metav1.GetControllerOf(test.revision); foundParent == nil || - foundParent.UID != test.parent.GetUID() { + if !metav1.IsControlledBy(test.revision, test.parent) { return true, nil, errors.NewInvalid( test.revision.GroupVersionKind().GroupKind(), test.revision.Name, nil) } @@ -1258,7 +1257,7 @@ func TestRealHistory_ReleaseControllerRevision(t *testing.T) { if adopted == nil { return } - if owner := metav1.GetControllerOf(adopted); owner != nil && owner.UID == test.parent.GetUID() { + if metav1.IsControlledBy(adopted, test.parent) { t.Errorf("%s: release failed", test.name) } } @@ -1386,7 +1385,7 @@ func TestFakeHistory_ReleaseControllerRevision(t *testing.T) { if adopted == nil { return } - if owner := metav1.GetControllerOf(adopted); owner != nil && owner.UID == test.parent.GetUID() { + if metav1.IsControlledBy(adopted, test.parent) { t.Errorf("%s: release failed", test.name) } } diff --git a/pkg/kubectl/history.go b/pkg/kubectl/history.go index 4e3edb83ec..625bbda8ac 100644 --- a/pkg/kubectl/history.go +++ b/pkg/kubectl/history.go @@ -271,11 +271,10 @@ func controlledHistories(c externalclientset.Interface, namespace, name string) } for i := range historyList.Items { history := historyList.Items[i] - // Skip history that doesn't belong to the DaemonSet - if controllerRef := metav1.GetControllerOf(&history); controllerRef == nil || controllerRef.UID != ds.UID { - continue + // Only add history that belongs to the DaemonSet + if metav1.IsControlledBy(&history, ds) { + result = append(result, &history) } - result = append(result, &history) } return ds, result, nil } diff --git a/test/e2e/apps/daemon_set.go b/test/e2e/apps/daemon_set.go index 86422035b8..17a00686f6 100644 --- a/test/e2e/apps/daemon_set.go +++ b/test/e2e/apps/daemon_set.go @@ -630,7 +630,7 @@ func checkDaemonPodOnNodes(f *framework.Framework, ds *extensions.DaemonSet, nod nodesToPodCount := make(map[string]int) for _, pod := range pods { - if controllerRef := metav1.GetControllerOf(&pod); controllerRef == nil || controllerRef.UID != ds.UID { + if !metav1.IsControlledBy(&pod, ds) { continue } if pod.DeletionTimestamp != nil { @@ -726,7 +726,7 @@ func checkDaemonPodsImageAndAvailability(c clientset.Interface, ds *extensions.D unavailablePods := 0 allImagesUpdated := true for _, pod := range pods { - if controllerRef := metav1.GetControllerOf(&pod); controllerRef == nil || controllerRef.UID != ds.UID { + if !metav1.IsControlledBy(&pod, ds) { continue } podImage := pod.Spec.Containers[0].Image