@@ -20,20 +20,47 @@ package transformerconfig
20
20
21
21
import (
22
22
"log"
23
+ "sort"
23
24
24
25
"github.com/ghodss/yaml"
25
26
"sigs.k8s.io/kustomize/pkg/ifc"
26
27
"sigs.k8s.io/kustomize/pkg/transformerconfig/defaultconfig"
27
28
)
28
29
30
+ type rpcSlice []ReferencePathConfig
31
+
32
+ func (s rpcSlice ) Len () int { return len (s ) }
33
+ func (s rpcSlice ) Swap (i , j int ) { s [i ], s [j ] = s [j ], s [i ] }
34
+ func (s rpcSlice ) Less (i , j int ) bool {
35
+ return s [i ].Gvk .IsLessThan (s [j ].Gvk )
36
+ }
37
+
38
+ type pcSlice []PathConfig
39
+
40
+ func (s pcSlice ) Len () int { return len (s ) }
41
+ func (s pcSlice ) Swap (i , j int ) { s [i ], s [j ] = s [j ], s [i ] }
42
+ func (s pcSlice ) Less (i , j int ) bool {
43
+ return s [i ].Gvk .IsLessThan (s [j ].Gvk )
44
+ }
45
+
29
46
// TransformerConfig represents the path configurations for different transformations
30
47
type TransformerConfig struct {
31
- NamePrefix []PathConfig `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
32
- NameSpace []PathConfig `json:"namespace,omitempty" yaml:"namespace,omitempty"`
33
- CommonLabels []PathConfig `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
34
- CommonAnnotations []PathConfig `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
35
- NameReference []ReferencePathConfig `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
36
- VarReference []PathConfig `json:"varReference,omitempty" yaml:"varReference,omitempty"`
48
+ NamePrefix pcSlice `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
49
+ NameSpace pcSlice `json:"namespace,omitempty" yaml:"namespace,omitempty"`
50
+ CommonLabels pcSlice `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
51
+ CommonAnnotations pcSlice `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
52
+ NameReference rpcSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
53
+ VarReference pcSlice `json:"varReference,omitempty" yaml:"varReference,omitempty"`
54
+ }
55
+
56
+ // sortFields provides determinism in logging, tests, etc.
57
+ func (t * TransformerConfig ) sortFields () {
58
+ sort .Sort (t .NamePrefix )
59
+ sort .Sort (t .NameSpace )
60
+ sort .Sort (t .CommonLabels )
61
+ sort .Sort (t .CommonAnnotations )
62
+ sort .Sort (t .NameReference )
63
+ sort .Sort (t .VarReference )
37
64
}
38
65
39
66
// AddPrefixPathConfig adds a PathConfig to NamePrefix
@@ -65,6 +92,7 @@ func (t *TransformerConfig) Merge(input *TransformerConfig) *TransformerConfig {
65
92
merged .CommonLabels = append (t .CommonLabels , input .CommonLabels ... )
66
93
merged .VarReference = append (t .VarReference , input .VarReference ... )
67
94
merged .NameReference = mergeNameReferencePathConfigs (t .NameReference , input .NameReference )
95
+ merged .sortFields ()
68
96
return merged
69
97
}
70
98
@@ -92,6 +120,7 @@ func MakeTransformerConfigFromBytes(data []byte) (*TransformerConfig, error) {
92
120
if err != nil {
93
121
return nil , err
94
122
}
123
+ t .sortFields ()
95
124
return & t , nil
96
125
}
97
126
0 commit comments