Skip to content

Commit 2579607

Browse files
petergardfjallk8s-ci-robot
authored andcommitted
🐛 deduplicate machine tags prior to openstack API apply call (#502)
* deduplicate machine tags prior to openstack API apply call * rename 'filtered' -> 'unique' * fix typo * set ci deadline to four minutes
1 parent 7042181 commit 2579607

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ linters:
1919
issue:
2020
max-same-issues: 0
2121
max-per-linter: 0
22+
run:
23+
deadline: 4m

pkg/cloud/services/compute/instance.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ package compute
1818

1919
import (
2020
"fmt"
21-
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
2221
"time"
2322

23+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
24+
2425
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/networking"
2526
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha2"
2627
"sigs.k8s.io/cluster-api/controllers/noderefutil"
@@ -90,6 +91,9 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
9091
// Append cluster scope tags
9192
machineTags = append(machineTags, openStackCluster.Spec.Tags...)
9293

94+
// tags need to be unique or the "apply tags" call will fail.
95+
machineTags = deduplicate(machineTags)
96+
9397
// Get security groups
9498
securityGroups, err := getSecurityGroups(s, openStackMachine.Spec.SecurityGroups)
9599
if err != nil {
@@ -537,3 +541,20 @@ func (s *Service) InstanceExists(openStackMachine *infrav1.OpenStackMachine) (in
537541
}
538542
return instanceList[0], nil
539543
}
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

Comments
 (0)