Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ linters:
issue:
max-same-issues: 0
max-per-linter: 0
run:
deadline: 4m
23 changes: 22 additions & 1 deletion pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package compute

import (
"fmt"
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
"time"

"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"

"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/services/networking"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha2"
"sigs.k8s.io/cluster-api/controllers/noderefutil"
Expand Down Expand Up @@ -90,6 +91,9 @@ func (s *Service) InstanceCreate(clusterName string, machine *clusterv1.Machine,
// Append cluster scope tags
machineTags = append(machineTags, openStackCluster.Spec.Tags...)

// tags need to be unique or the "apply tags" call will fail.
machineTags = deduplicate(machineTags)

// Get security groups
securityGroups, err := getSecurityGroups(s, openStackMachine.Spec.SecurityGroups)
if err != nil {
Expand Down Expand Up @@ -537,3 +541,20 @@ func (s *Service) InstanceExists(openStackMachine *infrav1.OpenStackMachine) (in
}
return instanceList[0], nil
}

// deduplicate takes a slice of input strings and filters out any duplicate
// string occurrences, for example making ["a", "b", "a", "c"] become ["a", "b",
// "c"].
func deduplicate(sequence []string) []string {
var unique []string
set := make(map[string]bool)

for _, s := range sequence {
if _, ok := set[s]; !ok {
unique = append(unique, s)
set[s] = true
}
}

return unique
}