@@ -3,6 +3,7 @@ package generators
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "github.com/bmatcuk/doublestar/v4"
6
7
"path"
7
8
"sort"
8
9
"strconv"
@@ -100,15 +101,17 @@ func (g *GitGenerator) generateParamsForGitDirectories(appSetGenerator *argoproj
100
101
101
102
func (g * GitGenerator ) generateParamsForGitFiles (appSetGenerator * argoprojiov1alpha1.ApplicationSetGenerator , useGoTemplate bool , goTemplateOptions []string ) ([]map [string ]interface {}, error ) {
102
103
103
- // Get all files that match the requested path string, removing duplicates
104
+ // Get all files that match the requested path string but are not configured as excludes , removing duplicates
104
105
allFiles := make (map [string ][]byte )
105
106
for _ , requestedPath := range appSetGenerator .Git .Files {
106
- files , err := g .repos .GetFiles (context .TODO (), appSetGenerator .Git .RepoURL , appSetGenerator .Git .Revision , requestedPath .Path )
107
- if err != nil {
108
- return nil , err
109
- }
110
- for filePath , content := range files {
111
- allFiles [filePath ] = content
107
+ if ! requestedPath .Exclude {
108
+ files , err := g .repos .GetFiles (context .TODO (), appSetGenerator .Git .RepoURL , appSetGenerator .Git .Revision , requestedPath .Path )
109
+ if err != nil {
110
+ return nil , err
111
+ }
112
+ for filePath , content := range files {
113
+ allFiles [filePath ] = content
114
+ }
112
115
}
113
116
}
114
117
@@ -120,9 +123,11 @@ func (g *GitGenerator) generateParamsForGitFiles(appSetGenerator *argoprojiov1al
120
123
}
121
124
sort .Strings (allPaths )
122
125
126
+ filteredPaths := g .filterFilePaths (appSetGenerator .Git .Files , allPaths )
127
+
123
128
// Generate params from each path, and return
124
129
res := []map [string ]interface {}{}
125
- for _ , path := range allPaths {
130
+ for _ , path := range filteredPaths {
126
131
127
132
// A JSON / YAML file path can contain multiple sets of parameters (ie it is an array)
128
133
paramsArray , err := g .generateParamsFromGitFile (path , allFiles [path ], appSetGenerator .Git .Values , useGoTemplate , goTemplateOptions , appSetGenerator .Git .PathParamPrefix )
@@ -212,7 +217,7 @@ func (g *GitGenerator) generateParamsFromGitFile(filePath string, fileContent []
212
217
return res , nil
213
218
}
214
219
215
- func (g * GitGenerator ) filterApps (Directories []argoprojiov1alpha1.GitDirectoryGeneratorItem , allPaths []string ) []string {
220
+ func (g * GitGenerator ) filterApps (Directories []argoprojiov1alpha1.GitGeneratorItem , allPaths []string ) []string {
216
221
res := []string {}
217
222
for _ , appPath := range allPaths {
218
223
appInclude := false
@@ -240,6 +245,36 @@ func (g *GitGenerator) filterApps(Directories []argoprojiov1alpha1.GitDirectoryG
240
245
return res
241
246
}
242
247
248
+ func (g * GitGenerator ) filterFilePaths (Files []argoprojiov1alpha1.GitGeneratorItem , allPaths []string ) []string {
249
+ res := []string {}
250
+ for _ , itemPath := range allPaths {
251
+ include := false
252
+ exclude := false
253
+ for _ , requestedPath := range Files {
254
+ // exec doublestar.Match only on excluded requestedPaths to stay backwards-compatible with the default
255
+ // greedy git file generator globbing
256
+ if requestedPath .Exclude {
257
+ match , err := doublestar .Match (requestedPath .Path , itemPath )
258
+ if err != nil {
259
+ log .WithError (err ).WithField ("requestedPath" , requestedPath ).
260
+ WithField ("appPath" , itemPath ).Error ("error while matching appPath to requestedPath" )
261
+ continue
262
+ }
263
+ if match {
264
+ exclude = true
265
+ }
266
+ } else {
267
+ include = true
268
+ }
269
+ }
270
+ // Whenever there is a path with exclude: true it wont be included, even if it is included in a different path pattern
271
+ if include && ! exclude {
272
+ res = append (res , itemPath )
273
+ }
274
+ }
275
+ return res
276
+ }
277
+
243
278
func (g * GitGenerator ) generateParamsFromApps (requestedApps []string , appSetGenerator * argoprojiov1alpha1.ApplicationSetGenerator , useGoTemplate bool , goTemplateOptions []string ) ([]map [string ]interface {}, error ) {
244
279
res := make ([]map [string ]interface {}, len (requestedApps ))
245
280
for i , a := range requestedApps {
0 commit comments