-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow deletion of node finalizer without passing checks
Longhorn 7475 Signed-off-by: Eric Weber <eric.weber@suse.com>
- Loading branch information
Showing
3 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2" | ||
) | ||
|
||
func TestIsRemovingLonghornFinalizer(t *testing.T) { | ||
assert := assert.New(t) | ||
now := v1.Now() | ||
|
||
tests := map[string]struct { | ||
oldObj runtime.Object | ||
newObj runtime.Object | ||
want bool | ||
wantErr bool | ||
}{ | ||
"notBeingDeleted": { | ||
oldObj: &longhorn.Node{}, | ||
newObj: &longhorn.Node{}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
"lessThanOneFinalizerRemoved": { | ||
oldObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{longhornFinalizerKey, "otherFinalizer"}, | ||
}, | ||
}, | ||
newObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{longhornFinalizerKey, "otherFinalizer"}, | ||
}, | ||
}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
"moreThanOneFinalizerRemoved": { | ||
oldObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{longhornFinalizerKey, "otherFinalizer"}, | ||
}, | ||
}, | ||
newObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
}, | ||
}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
"noLonghornFinalizerInOld": { | ||
oldObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{"otherFinalizer"}, | ||
}, | ||
}, | ||
newObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{}, | ||
}, | ||
}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
"longhornFinalizerInNew": { | ||
oldObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{longhornFinalizerKey, "otherFinalizer"}, | ||
}, | ||
}, | ||
newObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{longhornFinalizerKey}, | ||
}, | ||
}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
"correctConditions": { | ||
oldObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{longhornFinalizerKey, "otherFinalizer"}, | ||
}, | ||
}, | ||
newObj: &longhorn.Node{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
DeletionTimestamp: &now, | ||
Finalizers: []string{"otherFinalizer"}, | ||
}, | ||
}, | ||
want: true, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got, err := IsRemovingLonghornFinalizer(tc.oldObj, tc.newObj) | ||
assert.Equal(got, tc.want) | ||
if tc.wantErr { | ||
assert.Error(err) | ||
} else { | ||
assert.NoError(err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters