diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 0bff67aa6..322a3fe75 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1113,18 +1113,6 @@ func addRestoreLabels(obj metav1.Object, restoreName, backupName string) { obj.SetLabels(labels) } -// hasControllerOwner returns whether or not an object has a controller -// owner ref. Used to identify whether or not an object should be explicitly -// recreated during a restore. -func hasControllerOwner(refs []metav1.OwnerReference) bool { - for _, ref := range refs { - if ref.Controller != nil && *ref.Controller { - return true - } - } - return false -} - // isCompleted returns whether or not an object is considered completed. // Used to identify whether or not an object should be restored. Only Jobs or Pods are considered func isCompleted(obj *unstructured.Unstructured, groupResource schema.GroupResource) (bool, error) { diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index c7ff98346..5d2db3b07 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1222,69 +1222,6 @@ func (w *fakeWatch) ResultChan() <-chan watch.Event { return make(chan watch.Event) } -func TestHasControllerOwner(t *testing.T) { - tests := []struct { - name string - object map[string]interface{} - expectOwner bool - }{ - { - name: "missing metadata", - object: map[string]interface{}{}, - }, - { - name: "missing ownerReferences", - object: map[string]interface{}{ - "metadata": map[string]interface{}{}, - }, - expectOwner: false, - }, - { - name: "have ownerReferences, no controller fields", - object: map[string]interface{}{ - "metadata": map[string]interface{}{ - "ownerReferences": []interface{}{ - map[string]interface{}{"foo": "bar"}, - }, - }, - }, - expectOwner: false, - }, - { - name: "have ownerReferences, controller=false", - object: map[string]interface{}{ - "metadata": map[string]interface{}{ - "ownerReferences": []interface{}{ - map[string]interface{}{"controller": false}, - }, - }, - }, - expectOwner: false, - }, - { - name: "have ownerReferences, controller=true", - object: map[string]interface{}{ - "metadata": map[string]interface{}{ - "ownerReferences": []interface{}{ - map[string]interface{}{"controller": false}, - map[string]interface{}{"controller": false}, - map[string]interface{}{"controller": true}, - }, - }, - }, - expectOwner: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - u := &unstructured.Unstructured{Object: test.object} - hasOwner := hasControllerOwner(u.GetOwnerReferences()) - assert.Equal(t, test.expectOwner, hasOwner) - }) - } -} - func TestResetMetadataAndStatus(t *testing.T) { tests := []struct { name string