@@ -25,6 +25,7 @@ import (
25
25
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
26
26
"github.com/scaleway/scaleway-sdk-go/api/lb/v1"
27
27
"github.com/scaleway/scaleway-sdk-go/scw"
28
+ "golang.org/x/exp/maps"
28
29
v1 "k8s.io/api/core/v1"
29
30
"k8s.io/apimachinery/pkg/fields"
30
31
"k8s.io/apimachinery/pkg/util/runtime"
@@ -201,18 +202,19 @@ func (s *syncController) syncNodeTags(node *v1.Node) error {
201
202
patcher := NewNodePatcher (s .clientSet , nodeCopied )
202
203
203
204
nodeLabels := map [string ]string {}
204
- nodeTaints := []v1.Taint {}
205
+ // Note: taints must be unique by key and effect pair
206
+ nodeTaints := map [string ]v1.Taint {}
205
207
for _ , tag := range server .Server .Tags {
206
208
if strings .HasPrefix (tag , labelTaintPrefix ) {
207
209
key , value , effect := tagTaintParser (tag )
208
210
if key == "" {
209
211
continue
210
212
}
211
- nodeTaints = append ( nodeTaints , v1.Taint {
213
+ nodeTaints [ fmt . Sprintf ( "%s:%s" , key , effect )] = v1.Taint {
212
214
Key : key ,
213
215
Value : value ,
214
216
Effect : effect ,
215
- })
217
+ }
216
218
} else {
217
219
var key string
218
220
var value string
@@ -251,12 +253,13 @@ func (s *syncController) syncNodeTags(node *v1.Node) error {
251
253
}
252
254
253
255
for _ , taint := range node .Spec .Taints {
254
- if ! strings .HasPrefix (taint .Key , taintsPrefix ) {
255
- nodeTaints = append (nodeTaints , taint )
256
+ taintUniqueKey := fmt .Sprintf ("%s:%s" , taint .Key , taint .Effect )
257
+ if _ , ok := nodeTaints [taintUniqueKey ]; ! ok && ! strings .HasPrefix (taint .Key , taintsPrefix ) {
258
+ nodeTaints [taintUniqueKey ] = taint
256
259
}
257
260
}
258
261
259
- nodeCopied .Spec .Taints = nodeTaints
262
+ nodeCopied .Spec .Taints = maps . Values ( nodeTaints )
260
263
err = patcher .Patch ()
261
264
if err != nil {
262
265
klog .Errorf ("error patching service: %v" , err )
0 commit comments