Support remote resources for kustomize edit add

This commit is contained in:
Kevin Wang
2020-07-24 12:24:59 -07:00
parent 51f9a84358
commit 2ee4eec791
4 changed files with 91 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import (
"strings"
"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/api/ifc"
)
// GlobPatterns accepts a slice of glob strings and returns the set of
@@ -29,6 +30,32 @@ func GlobPatterns(fSys filesys.FileSystem, patterns []string) ([]string, error)
return result, nil
}
// GlobPatterns accepts a slice of glob strings and returns the set of
// matching file paths. If files are not found, will try load from remote.
func GlobPatternsWithLoader(fSys filesys.FileSystem, ldr ifc.Loader, patterns []string) ([]string, error) {
var result []string
for _, pattern := range patterns {
files, err := fSys.Glob(pattern)
if err != nil {
return nil, err
}
if len(files) == 0 {
loader, err := ldr.New(pattern)
if err != nil {
log.Printf("%s has no match", pattern)
} else {
result = append(result, pattern)
if loader != nil {
loader.Cleanup()
}
}
continue
}
result = append(result, files...)
}
return result, nil
}
// ConvertToMap converts a slice of strings in the form of
// `key:value` into a map.
func ConvertToMap(input string, kind string) (map[string]string, error) {