support different filenames for kustomization file

This commit is contained in:
Jingfang Liu
2019-01-24 12:26:59 -08:00
parent 028724df08
commit f7a59178a8
10 changed files with 50 additions and 38 deletions

View File

@@ -82,18 +82,23 @@ func NewKustTarget(
}
func loadKustFile(ldr ifc.Loader) ([]byte, error) {
for _, kf := range []string{
constants.KustomizationFileName,
constants.SecondaryKustomizationFileName} {
content, err := ldr.Load(kf)
var content []byte
match := 0
for _, kf := range constants.KustomizationFileNames {
c, err := ldr.Load(kf)
if err == nil {
return content, nil
}
if !strings.Contains(err.Error(), "no such file or directory") {
return nil, err
match += 1
content = c
}
}
return nil, fmt.Errorf("no kustomization.yaml file under %s", ldr.Root())
switch match {
case 0:
return nil, fmt.Errorf("no kustomization.yaml file under %s", ldr.Root())
case 1:
return content, nil
default:
return nil, fmt.Errorf("Found multiple kustomization file under: %s\n", ldr.Root())
}
}
func unmarshal(y []byte, o interface{}) error {