diff --git a/pkg/flag/kubernetes_flags.go b/pkg/flag/kubernetes_flags.go index a6e8b563a1dc..fd560e7defc4 100644 --- a/pkg/flag/kubernetes_flags.go +++ b/pkg/flag/kubernetes_flags.go @@ -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 diff --git a/pkg/flag/kubernetes_flags_test.go b/pkg/flag/kubernetes_flags_test.go new file mode 100644 index 000000000000..50c0b4f793bf --- /dev/null +++ b/pkg/flag/kubernetes_flags_test.go @@ -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) + }) + } +}