@@ -64,16 +64,27 @@ func LoadValues() error {
6464}
6565
6666func filterValuesFiles (valuesFiles []string , dirLimit string ) []string {
67+ // If dirLimit points to a secret file, extract its directory
68+ if strings .HasSuffix (dirLimit , ".gitops.secret.enc.yaml" ) || strings .HasSuffix (dirLimit , ".gitops.secret.enc.yml" ) {
69+ dirLimit = filepath .Dir (dirLimit )
70+ log .Debugf ("Converted file-based dir limit to directory: %q" , dirLimit )
71+ }
72+
6773 dirLimitNormalized := normalizeDirPath (dirLimit )
74+ log .Debugf ("Filtering values files with dirLimit=%q normalized=%q" , dirLimit , dirLimitNormalized )
6875 if dirLimitNormalized == "" {
6976 return valuesFiles
7077 }
7178
7279 filtered := make ([]string , 0 , len (valuesFiles ))
7380 for _ , valuesFile := range valuesFiles {
7481 valuesDir := normalizeDirPath (filepath .Dir (valuesFile ))
75- if shouldIncludeValuesFile (valuesDir , dirLimitNormalized ) {
82+ include := shouldIncludeValuesFile (valuesDir , dirLimitNormalized )
83+ log .Debugf ("Evaluating values file %q dir=%q normalizedDir=%q include=%v" , valuesFile , filepath .Dir (valuesFile ), valuesDir , include )
84+ if include {
7685 filtered = append (filtered , valuesFile )
86+ } else {
87+ log .Debugf ("Excluding values file %q due to dir limit %q" , valuesFile , dirLimitNormalized )
7788 }
7889 }
7990 return filtered
@@ -124,26 +135,34 @@ func (t TemplateValues) merge() {
124135 sort .SliceStable (t , func (i , j int ) bool {
125136 return len (strings .Split (t [i ].Path , "/" )) < len (strings .Split (t [j ].Path , "/" ))
126137 })
138+ order := make ([]string , len (t ))
139+ for idx , tv := range t {
140+ order [idx ] = tv .Path
141+ }
142+ log .Debugf ("TemplateValues merge order: %v" , order )
127143 for i , templateValue := range t {
128- merged := false
129- for j , templateValue2 := range t {
130- if j >= i {
131- break
132- }
133-
134- if strings .HasPrefix (templateValue .Path , templateValue2 .Path ) {
135- merged = true
136- templateValue .MergedValues = mergeMaps (templateValue2 .MergedValues , templateValue .Values )
144+ var bestParent * TemplateValuesPath
145+ for j := i - 1 ; j >= 0 ; j -- {
146+ candidate := t [j ]
147+ log .Debugf ("Considering ancestor candidate %q for child %q" , candidate .Path , templateValue .Path )
148+ if strings .HasPrefix (templateValue .Path , candidate .Path ) {
149+ bestParent = candidate
137150 break
138151 }
139152 }
140- if ! merged {
153+
154+ if bestParent != nil {
155+ log .Debugf ("Merging ancestor %q into %q" , bestParent .Path , templateValue .Path )
156+ templateValue .MergedValues = mergeMaps (bestParent .MergedValues , templateValue .Values )
157+ } else {
158+ log .Debugf ("No ancestor found for %q, using own values only" , templateValue .Path )
141159 templateValue .MergedValues = templateValue .Values
142160 }
143161 }
144162}
145163
146164func GetValuesForPath (path string ) map [interface {}]interface {} {
165+ log .Debugf ("Resolving values for secret path %q" , path )
147166 if ! loaded {
148167 err := LoadValues ()
149168 if err != nil {
@@ -154,17 +173,19 @@ func GetValuesForPath(path string) map[interface{}]interface{} {
154173 usedPath := ""
155174 maxPathLength := 0
156175 for _ , templateValue := range templateValues {
176+ log .Debugf ("Considering values prefix %q for path %q" , templateValue .Path , path )
157177 if strings .HasPrefix (path , templateValue .Path ) && len (templateValue .Path ) > maxPathLength {
158178 maxPathLength = len (templateValue .Path )
159179 usedPath = templateValue .Path
160180 values = templateValue .MergedValues
181+ log .Debugf ("Selecting values prefix %q for path %q" , templateValue .Path , path )
161182 }
162183 }
163184
164185 if usedPath != "" {
165- log .Tracef ("Using values from %s for path %s" , usedPath , path )
186+ log .Debugf ("Using values from %s for path %s" , usedPath , path )
166187 } else {
167- log .Tracef ("No values found for path %s" , path )
188+ log .Debugf ("No values found for path %s" , path )
168189 }
169190
170191 return values
0 commit comments