@@ -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+
3944func 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