Skip to content

Commit 75e9e35

Browse files
committed
fix(api): configmaps items generated in order
1 parent 311dbbf commit 75e9e35

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

api/internal/generators/configmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func MakeConfigMap(
3737
if err != nil {
3838
return nil, err
3939
}
40-
if err = rn.LoadMapIntoConfigMapData(m); err != nil {
40+
if err = rn.LoadMapIntoConfigMapData(m.values); err != nil {
4141
return nil, err
4242
}
4343
err = copyLabelsAndAnnotations(rn, args.Options)

api/internal/generators/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func MakeSecret(
5050
if err != nil {
5151
return nil, err
5252
}
53-
if err = rn.LoadMapIntoSecretData(m); err != nil {
53+
if err = rn.LoadMapIntoSecretData(m.values); err != nil {
5454
return nil, err
5555
}
5656
copyLabelsAndAnnotations(rn, args.Options)

api/internal/generators/utils.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,38 @@ kind: %s
3636
return rn, nil
3737
}
3838

39+
type orderedMap struct {
40+
keys []string
41+
values map[string]string
42+
}
43+
3944
func makeValidatedDataMap(
40-
ldr ifc.KvLoader, name string, sources types.KvPairSources) (map[string]string, error) {
45+
ldr ifc.KvLoader, name string, sources types.KvPairSources,
46+
) (orderedMap, error) {
47+
4148
pairs, err := ldr.Load(sources)
4249
if err != nil {
43-
return nil, errors.WrapPrefix(err, "loading KV pairs", 0)
50+
return orderedMap{}, errors.WrapPrefix(err, "loading KV pairs", 0)
4451
}
45-
knownKeys := make(map[string]string)
52+
53+
seen := make(map[string]struct{})
54+
values := make(map[string]string, len(pairs))
55+
var keys []string
56+
4657
for _, p := range pairs {
47-
// legal key: alphanumeric characters, '-', '_' or '.'
4858
if err := ldr.Validator().ErrIfInvalidKey(p.Key); err != nil {
49-
return nil, err
59+
return orderedMap{}, err
5060
}
51-
if _, ok := knownKeys[p.Key]; ok {
52-
return nil, errors.Errorf(
61+
if _, dup := seen[p.Key]; dup {
62+
return orderedMap{}, errors.Errorf(
5363
"configmap %s illegally repeats the key `%s`", name, p.Key)
5464
}
55-
knownKeys[p.Key] = p.Value
65+
seen[p.Key] = struct{}{}
66+
keys = append(keys, p.Key)
67+
values[p.Key] = p.Value
5668
}
57-
return knownKeys, nil
69+
70+
return orderedMap{keys: keys, values: values}, nil
5871
}
5972

6073
// copyLabelsAndAnnotations copies labels and annotations from

0 commit comments

Comments
 (0)