Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the deletion behavior #275

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/kwok/controllers/finalizers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ func finalizersModify(metaFinalizers []string, finalizers *internalversion.Stage
ops = append(ops, finalizersAdd(metaFinalizers, finalizers.Add)...)
}
} else {
ops = append(ops, finalizersEmpty)
if len(metaFinalizers) != 0 {
ops = append(ops, finalizersEmpty)
}

if len(finalizers.Add) != 0 {
ops = append(ops, finalizersAdd(nil, finalizers.Add)...)
}
Expand Down
73 changes: 73 additions & 0 deletions pkg/kwok/controllers/finalizers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,76 @@ func Test_finalizersRemove(t *testing.T) {
})
}
}

func Test_finalizersModify(t *testing.T) {
type args struct {
metaFinalizers []string
finalizers *internalversion.StageFinalizers
}
tests := []struct {
name string
args args
want []jsonpathOperation
}{
{
args: args{
metaFinalizers: nil,
finalizers: &internalversion.StageFinalizers{
Empty: true,
},
},
want: nil,
},
{
args: args{
metaFinalizers: []string{"a"},
finalizers: &internalversion.StageFinalizers{
Empty: true,
},
},
want: []jsonpathOperation{
{Op: "remove", Path: "/metadata/finalizers", Value: nil},
},
},
{
args: args{
metaFinalizers: []string{"a"},
finalizers: &internalversion.StageFinalizers{
Empty: true,
Add: []internalversion.FinalizerItem{
{
Value: "b",
},
},
},
},
want: []jsonpathOperation{
{Op: "remove", Path: "/metadata/finalizers", Value: nil},
{Op: "add", Path: "/metadata/finalizers", Value: []string{"b"}},
},
},
{
args: args{
metaFinalizers: nil,
finalizers: &internalversion.StageFinalizers{
Empty: true,
Add: []internalversion.FinalizerItem{
{
Value: "b",
},
},
},
},
want: []jsonpathOperation{
{Op: "add", Path: "/metadata/finalizers", Value: []string{"b"}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := finalizersModify(tt.args.metaFinalizers, tt.args.finalizers); !reflect.DeepEqual(got, tt.want) {
t.Errorf("finalizersModify() = %v, want %v", got, tt.want)
}
})
}
}