mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 11:46:06 +00:00
Merge pull request #1598 from skriss/rm-has-controller-owner
remove unused hasControllerOwner func and tests
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user