@@ -35,8 +35,7 @@ import (
35
35
)
36
36
37
37
const (
38
- kustomizationFileName = "kustomization.yaml"
39
- transformerFileName = "kustomization-gc-labels.yaml"
38
+ transformerFileName = "kustomization-gc-labels.yaml"
40
39
)
41
40
42
41
type KustomizeGenerator struct {
@@ -50,7 +49,7 @@ func NewGenerator(kustomization kustomizev1.Kustomization) *KustomizeGenerator {
50
49
}
51
50
52
51
func (kg * KustomizeGenerator ) WriteFile (dirPath string ) (string , error ) {
53
- kfile := filepath .Join (dirPath , kustomizationFileName )
52
+ kfile := filepath .Join (dirPath , konfig . DefaultKustomizationFileName () )
54
53
55
54
checksum , err := kg .checksum (dirPath )
56
55
if err != nil {
@@ -129,7 +128,14 @@ func checkKustomizeImageExists(images []kustypes.Image, imageName string) (bool,
129
128
130
129
func (kg * KustomizeGenerator ) generateKustomization (dirPath string ) error {
131
130
fs := filesys .MakeFsOnDisk ()
132
- kfile := filepath .Join (dirPath , kustomizationFileName )
131
+
132
+ // Determine if there already is a Kustomization file at the root,
133
+ // as this means we do not have to generate one.
134
+ for _ , kfilename := range konfig .RecognizedKustomizationFileNames () {
135
+ if kpath := filepath .Join (dirPath , kfilename ); fs .Exists (kpath ) && ! fs .IsDir (kpath ) {
136
+ return nil
137
+ }
138
+ }
133
139
134
140
scan := func (base string ) ([]string , error ) {
135
141
var paths []string
@@ -172,45 +178,42 @@ func (kg *KustomizeGenerator) generateKustomization(dirPath string) error {
172
178
return paths , err
173
179
}
174
180
175
- if _ , err := os .Stat (kfile ); err != nil {
176
- abs , err := filepath .Abs (dirPath )
177
- if err != nil {
178
- return err
179
- }
180
-
181
- files , err := scan (abs )
182
- if err != nil {
183
- return err
184
- }
181
+ abs , err := filepath .Abs (dirPath )
182
+ if err != nil {
183
+ return err
184
+ }
185
185
186
- f , err := fs .Create (kfile )
187
- if err != nil {
188
- return err
189
- }
190
- f .Close ()
186
+ files , err := scan (abs )
187
+ if err != nil {
188
+ return err
189
+ }
191
190
192
- kus := kustypes. Kustomization {
193
- TypeMeta : kustypes. TypeMeta {
194
- APIVersion : kustypes . KustomizationVersion ,
195
- Kind : kustypes . KustomizationKind ,
196
- },
197
- }
191
+ kfile := filepath . Join ( dirPath , konfig . DefaultKustomizationFileName ())
192
+ f , err := fs . Create ( kfile )
193
+ if err != nil {
194
+ return err
195
+ }
196
+ f . Close ()
198
197
199
- var resources []string
200
- for _ , file := range files {
201
- resources = append (resources , strings .Replace (file , abs , "." , 1 ))
202
- }
198
+ kus := kustypes.Kustomization {
199
+ TypeMeta : kustypes.TypeMeta {
200
+ APIVersion : kustypes .KustomizationVersion ,
201
+ Kind : kustypes .KustomizationKind ,
202
+ },
203
+ }
203
204
204
- kus .Resources = resources
205
- kd , err := yaml .Marshal (kus )
206
- if err != nil {
207
- return err
208
- }
205
+ var resources []string
206
+ for _ , file := range files {
207
+ resources = append (resources , strings .Replace (file , abs , "." , 1 ))
208
+ }
209
209
210
- return ioutil .WriteFile (kfile , kd , os .ModePerm )
210
+ kus .Resources = resources
211
+ kd , err := yaml .Marshal (kus )
212
+ if err != nil {
213
+ return err
211
214
}
212
215
213
- return nil
216
+ return ioutil . WriteFile ( kfile , kd , os . ModePerm )
214
217
}
215
218
216
219
func (kg * KustomizeGenerator ) checksum (dirPath string ) (string , error ) {
0 commit comments