@@ -8,25 +8,49 @@ import (
8
8
"strings"
9
9
10
10
"github.com/pkg/errors"
11
+ "github.com/rs/zerolog/log"
11
12
"sigs.k8s.io/kustomize/api/types"
12
13
"sigs.k8s.io/kustomize/kyaml/yaml"
13
14
)
14
15
15
16
// ProcessKustomizationFile processes a kustomization file and returns all the files and directories it references.
16
- func ProcessKustomizationFile (sourceFS fs.FS , relKustomizationPath string ) (files [] string , dirs []string , err error ) {
17
+ func ProcessKustomizationFile (sourceFS fs.FS , relKustomizationPath string ) (files , dirs []string , err error ) {
17
18
dirName := filepath .Dir (relKustomizationPath )
18
- return processDir (sourceFS , dirName )
19
+
20
+ proc := processor {
21
+ visitedDirs : make (map [string ]struct {}),
22
+ }
23
+
24
+ files , dirs , err = proc .processDir (sourceFS , dirName )
25
+ if err != nil {
26
+ return nil , nil , errors .Wrapf (err , "failed to process kustomize file %q" , relKustomizationPath )
27
+ }
28
+
29
+ return files , dirs , nil
30
+ }
31
+
32
+ type processor struct {
33
+ visitedDirs map [string ]struct {}
19
34
}
20
35
21
- func processDir (sourceFS fs.FS , relBase string ) (files []string , dirs []string , err error ) {
36
+ func (p processor ) processDir (sourceFS fs.FS , relBase string ) (files , dirs []string , err error ) {
37
+ if _ , ok := p .visitedDirs [relBase ]; ok {
38
+ log .Warn ().Msgf ("directory %q already processed" , relBase )
39
+ return nil , nil , nil
40
+ }
41
+
42
+ log .Info ().Msgf ("processing directory %q" , relBase )
43
+ p .visitedDirs [relBase ] = struct {}{}
44
+
22
45
absKustPath := filepath .Join (relBase , "kustomization.yaml" )
23
46
24
47
// Parse using official Kustomization type
25
48
file , err := sourceFS .Open (absKustPath )
26
49
if err != nil {
27
50
if os .IsNotExist (err ) {
28
- return nil , nil , nil // No kustomization.yaml in this directory
51
+ return nil , [] string { relBase } , nil // No kustomization.yaml in this directory, the dir is the important thing
29
52
}
53
+
30
54
return nil , nil , errors .Wrapf (err , "failed to open file %q" , absKustPath )
31
55
}
32
56
@@ -53,6 +77,10 @@ func processDir(sourceFS fs.FS, relBase string) (files []string, dirs []string,
53
77
files = append (files , kust .Crds ... )
54
78
files = append (files , kust .Transformers ... )
55
79
80
+ for _ , helm := range kust .HelmCharts {
81
+ files = append (files , helm .ValuesFile )
82
+ }
83
+
56
84
for _ , patch := range kust .Patches {
57
85
if patch .Path != "" {
58
86
files = append (files , patch .Path )
@@ -93,13 +121,12 @@ func processDir(sourceFS fs.FS, relBase string) (files []string, dirs []string,
93
121
}
94
122
}
95
123
96
- // We now know this directory has a kustomization.yaml, so add it to "dirs".
97
- allDirs := append ([]string (nil ), relBase )
98
124
allFiles := append ([]string (nil ), files ... )
125
+ var allDirs []string
99
126
100
127
// process directories and add them
101
128
for _ , relResource := range directories {
102
- subFiles , subDirs , err := processDir (sourceFS , relResource )
129
+ subFiles , subDirs , err := p . processDir (sourceFS , relResource )
103
130
if err != nil {
104
131
return nil , nil , errors .Wrapf (err , "failed to process %q" , relResource )
105
132
}
0 commit comments