@@ -18,9 +18,10 @@ package compute
18
18
19
19
import (
20
20
"fmt"
21
- "sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
22
21
"time"
23
22
23
+ "sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
24
+
24
25
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/networking"
25
26
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha2"
26
27
"sigs.k8s.io/cluster-api/controllers/noderefutil"
@@ -90,6 +91,9 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
90
91
// Append cluster scope tags
91
92
machineTags = append (machineTags , openStackCluster .Spec .Tags ... )
92
93
94
+ // tags need to be unique or the "apply tags" call will fail.
95
+ machineTags = deduplicate (machineTags )
96
+
93
97
// Get security groups
94
98
securityGroups , err := getSecurityGroups (s , openStackMachine .Spec .SecurityGroups )
95
99
if err != nil {
@@ -537,3 +541,20 @@ func (s *Service) InstanceExists(openStackMachine *infrav1.OpenStackMachine) (in
537
541
}
538
542
return instanceList [0 ], nil
539
543
}
544
+
545
+ // deduplicate takes a slice of input strings and filters out any duplicate
546
+ // string occurrences, for example making ["a", "b", "a", "c"] become ["a", "b",
547
+ // "c"].
548
+ func deduplicate (sequence []string ) []string {
549
+ var unique []string
550
+ set := make (map [string ]bool )
551
+
552
+ for _ , s := range sequence {
553
+ if _ , ok := set [s ]; ! ok {
554
+ unique = append (unique , s )
555
+ set [s ] = true
556
+ }
557
+ }
558
+
559
+ return unique
560
+ }
0 commit comments