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

@@ -129,12 +129,22 @@ func NewKustomizationFile(fSys fs.FileSystem) (*kustomizationFile, error) { // n
}
func (mf *kustomizationFile) validate() error {
if mf.fSys.Exists(constants.KustomizationFileName) {
mf.path = constants.KustomizationFileName
} else if mf.fSys.Exists(constants.SecondaryKustomizationFileName) {
mf.path = constants.SecondaryKustomizationFileName
} else {
return fmt.Errorf("Missing kustomization file '%s'.\n", constants.KustomizationFileName)
match := 0
var path []string
for _, kfilename := range constants.KustomizationFileNames {
if mf.fSys.Exists(kfilename) {
match += 1
path = append(path, kfilename)
}
}
switch match {
case 0:
return fmt.Errorf("Missing kustomization file '%s'.\n", constants.KustomizationFileNames[0])
case 1:
mf.path = path[0]
default:
return fmt.Errorf("Found multiple kustomization file: %v\n", path)
}
if mf.fSys.IsDir(mf.path) {

View File

@@ -159,12 +159,12 @@ configMapGenerator:
name: my-configmap
`
fakeFS := fs.MakeFakeFS()
fakeFS.WriteFile(constants.SecondaryKustomizationFileName, []byte(kcontent))
fakeFS.WriteFile(constants.KustomizationFileNames[1], []byte(kcontent))
k, err := NewKustomizationFile(fakeFS)
if err != nil {
t.Fatalf("Unexpected Error: %v", err)
}
if k.path != constants.SecondaryKustomizationFileName {
if k.path != constants.KustomizationFileNames[1] {
t.Fatalf("Load incorrect file path %s", k.path)
}
}