mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 09:02:53 +00:00
support different filenames for kustomization file
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user