Skip to content

Commit db5079d

Browse files
committed
capi: aws: report all conflicting user tags at once
Returning an error for each tag means a user would have to run the Installer multiple times to find out all the clobbered tags. Let's include all the conflicts at once in the error message. Also changed from the deprecated set syntax to the new generics style.
1 parent b8d5671 commit db5079d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

pkg/asset/machines/aws/awsmachines.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package aws
33

44
import (
55
"fmt"
6-
"sort"
76

87
v1 "k8s.io/api/core/v1"
98
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -130,21 +129,21 @@ func CapaTagsFromUserTags(clusterID string, usertags map[string]string) (capa.Ta
130129
tags := capa.Tags{}
131130
tags[fmt.Sprintf("kubernetes.io/cluster/%s", clusterID)] = "owned"
132131

133-
forbiddenTags := sets.NewString()
132+
forbiddenTags := sets.New[string]()
134133
for key := range tags {
135134
forbiddenTags.Insert(key)
136135
}
137136

138-
userTagKeys := make([]string, 0, len(usertags))
137+
userTagKeys := sets.New[string]()
139138
for key := range usertags {
140-
userTagKeys = append(userTagKeys, key)
139+
userTagKeys.Insert(key)
141140
}
142-
sort.Strings(userTagKeys)
143141

144-
for _, k := range userTagKeys {
145-
if forbiddenTags.Has(k) {
146-
return nil, fmt.Errorf("user tags may not clobber %s", k)
147-
}
142+
if clobberedTags := userTagKeys.Intersection(forbiddenTags); clobberedTags.Len() > 0 {
143+
return nil, fmt.Errorf("user tag keys %v are not allowed", sets.List(clobberedTags))
144+
}
145+
146+
for _, k := range sets.List(userTagKeys) {
148147
tags[k] = usertags[k]
149148
}
150149
return tags, nil

0 commit comments

Comments
 (0)