Skip to content

Commit

Permalink
Merge pull request #275 from wzshiming/fix/delete
Browse files Browse the repository at this point in the history
Fix the deletion behavior
  • Loading branch information
wzshiming authored Feb 11, 2023
2 parents b34a051 + 649ce91 commit 6c0518c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
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)
}
})
}
}

0 comments on commit 6c0518c

Please sign in to comment.