Skip to content

Commit

Permalink
fix: no schedule toleration (#5562)
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <[email protected]>
  • Loading branch information
chen-keinan authored Nov 14, 2023
1 parent 138feb0 commit 3891e3d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/flag/kubernetes_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ func optionToTolerations(tolerationsOptions []string) ([]corev1.Toleration, erro
if err != nil {
return nil, fmt.Errorf("TolerationSeconds must must be a number")
}
toleration.TolerationSeconds = lo.ToPtr(int64(tolerationSec))
}
toleration.TolerationSeconds = lo.ToPtr(int64(tolerationSec))
tolerations = append(tolerations, toleration)
}
return tolerations, nil
Expand Down
51 changes: 51 additions & 0 deletions pkg/flag/kubernetes_flags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package flag

import (
"testing"

"github.com/samber/lo"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)

func TestOptionToToleration(t *testing.T) {

tests := []struct {
name string
tolerationsOptions []string
want []corev1.Toleration
}{
{
name: "no execute",
tolerationsOptions: []string{"key1=CriticalAddonsOnly:NoExecute:3600"},
want: []corev1.Toleration{
{
Key: "key1",
Operator: "Equal",
Value: "CriticalAddonsOnly",
Effect: "NoExecute",
TolerationSeconds: lo.ToPtr(int64(3600)),
},
},
},
{
name: "no schedule",
tolerationsOptions: []string{"key1=CriticalAddonsOnly:NoSchedule"},
want: []corev1.Toleration{
{
Key: "key1",
Operator: "Equal",
Value: "CriticalAddonsOnly",
Effect: "NoSchedule",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := optionToTolerations(tt.tolerationsOptions)
assert.NoError(t, err)
assert.Equal(t, got, tt.want)
})
}
}

0 comments on commit 3891e3d

Please sign in to comment.