Migrate to IsControlledBy from meta/v1 package

pull/6/head
Mikhail Mazurskiy 2017-08-02 20:36:58 +10:00
parent 042b5642b9
commit 32b78aebf2
No known key found for this signature in database
GPG Key ID: 93551ECC96E2F568
5 changed files with 13 additions and 17 deletions

View File

@ -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 // ignore pods that belong to the daemonset when taking into account whether
// a daemonset should bind to a node. // a daemonset should bind to a node.
if controllerRef := metav1.GetControllerOf(pod); controllerRef != nil && controllerRef.UID == ds.UID { if metav1.IsControlledBy(pod, ds) {
continue continue
} }
pods = append(pods, pod) pods = append(pods, pod)

View File

@ -579,8 +579,7 @@ func ListReplicaSets(deployment *extensions.Deployment, getRSList RsListFunc) ([
// Only include those whose ControllerRef matches the Deployment. // Only include those whose ControllerRef matches the Deployment.
owned := make([]*extensions.ReplicaSet, 0, len(all)) owned := make([]*extensions.ReplicaSet, 0, len(all))
for _, rs := range all { for _, rs := range all {
controllerRef := metav1.GetControllerOf(rs) if metav1.IsControlledBy(rs, deployment) {
if controllerRef != nil && controllerRef.UID == deployment.UID {
owned = append(owned, rs) owned = append(owned, rs)
} }
} }
@ -603,8 +602,7 @@ func ListReplicaSetsInternal(deployment *internalextensions.Deployment, getRSLis
// Only include those whose ControllerRef matches the Deployment. // Only include those whose ControllerRef matches the Deployment.
filtered := make([]*internalextensions.ReplicaSet, 0, len(all)) filtered := make([]*internalextensions.ReplicaSet, 0, len(all))
for _, rs := range all { for _, rs := range all {
controllerRef := metav1.GetControllerOf(rs) if metav1.IsControlledBy(rs, deployment) {
if controllerRef != nil && controllerRef.UID == deployment.UID {
filtered = append(filtered, rs) filtered = append(filtered, rs)
} }
} }

View File

@ -992,7 +992,7 @@ func TestRealHistory_AdoptControllerRevision(t *testing.T) {
if !test.err && err != nil { if !test.err && err != nil {
t.Errorf("%s: %s", test.name, err) 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) t.Errorf("%s: adoption failed", test.name)
} }
if test.err && err == nil { if test.err && err == nil {
@ -1103,7 +1103,7 @@ func TestFakeHistory_AdoptControllerRevision(t *testing.T) {
if !test.err && err != nil { if !test.err && err != nil {
t.Errorf("%s: %s", test.name, err) 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) t.Errorf("%s: adoption failed", test.name)
} }
if test.err && err == nil { if test.err && err == nil {
@ -1211,8 +1211,7 @@ func TestRealHistory_ReleaseControllerRevision(t *testing.T) {
if found == nil { if found == nil {
return true, nil, errors.NewNotFound(apps.Resource("controllerrevisions"), test.revision.Name) return true, nil, errors.NewNotFound(apps.Resource("controllerrevisions"), test.revision.Name)
} }
if foundParent := metav1.GetControllerOf(test.revision); foundParent == nil || if !metav1.IsControlledBy(test.revision, test.parent) {
foundParent.UID != test.parent.GetUID() {
return true, nil, errors.NewInvalid( return true, nil, errors.NewInvalid(
test.revision.GroupVersionKind().GroupKind(), test.revision.Name, nil) test.revision.GroupVersionKind().GroupKind(), test.revision.Name, nil)
} }
@ -1258,7 +1257,7 @@ func TestRealHistory_ReleaseControllerRevision(t *testing.T) {
if adopted == nil { if adopted == nil {
return 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) t.Errorf("%s: release failed", test.name)
} }
} }
@ -1386,7 +1385,7 @@ func TestFakeHistory_ReleaseControllerRevision(t *testing.T) {
if adopted == nil { if adopted == nil {
return 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) t.Errorf("%s: release failed", test.name)
} }
} }

View File

@ -271,11 +271,10 @@ func controlledHistories(c externalclientset.Interface, namespace, name string)
} }
for i := range historyList.Items { for i := range historyList.Items {
history := historyList.Items[i] history := historyList.Items[i]
// Skip history that doesn't belong to the DaemonSet // Only add history that belongs to the DaemonSet
if controllerRef := metav1.GetControllerOf(&history); controllerRef == nil || controllerRef.UID != ds.UID { if metav1.IsControlledBy(&history, ds) {
continue result = append(result, &history)
} }
result = append(result, &history)
} }
return ds, result, nil return ds, result, nil
} }

View File

@ -630,7 +630,7 @@ func checkDaemonPodOnNodes(f *framework.Framework, ds *extensions.DaemonSet, nod
nodesToPodCount := make(map[string]int) nodesToPodCount := make(map[string]int)
for _, pod := range pods { for _, pod := range pods {
if controllerRef := metav1.GetControllerOf(&pod); controllerRef == nil || controllerRef.UID != ds.UID { if !metav1.IsControlledBy(&pod, ds) {
continue continue
} }
if pod.DeletionTimestamp != nil { if pod.DeletionTimestamp != nil {
@ -726,7 +726,7 @@ func checkDaemonPodsImageAndAvailability(c clientset.Interface, ds *extensions.D
unavailablePods := 0 unavailablePods := 0
allImagesUpdated := true allImagesUpdated := true
for _, pod := range pods { for _, pod := range pods {
if controllerRef := metav1.GetControllerOf(&pod); controllerRef == nil || controllerRef.UID != ds.UID { if !metav1.IsControlledBy(&pod, ds) {
continue continue
} }
podImage := pod.Spec.Containers[0].Image podImage := pod.Spec.Containers[0].Image