1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Ensure proper FS root is set while bootstrapping

This ensures relative paths to e.g. bases can be used.

Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
Hidde Beydals
2022-05-24 12:03:40 +02:00
parent 938f2570ef
commit 5130a154e4
4 changed files with 39 additions and 19 deletions

View File

@@ -138,14 +138,22 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
var kustomizeBuildMutex sync.Mutex
// Build takes the path to a directory with a konfig.RecognizedKustomizationFileNames,
// builds it, and returns the resulting manifests as multi-doc YAML.
// builds it, and returns the resulting manifests as multi-doc YAML. It restricts the
// Kustomize file system to the parent directory of the base.
func Build(base string) ([]byte, error) {
// TODO(hidde): drop this when consumers have moved away to BuildWithRoot.
parent := filepath.Dir(strings.TrimSuffix(base, string(filepath.Separator)))
return BuildWithRoot(parent, base)
}
// BuildWithRoot takes the path to a directory with a konfig.RecognizedKustomizationFileNames,
// builds it, and returns the resulting manifests as multi-doc YAML.
// The Kustomize file system is restricted to root.
func BuildWithRoot(root, base string) ([]byte, error) {
kustomizeBuildMutex.Lock()
defer kustomizeBuildMutex.Unlock()
// TODO(hidde): make this configurable to a specific root (relative to base)
parent := filepath.Dir(strings.TrimSuffix(base, string(filepath.Separator)))
fs, err := filesys.MakeFsOnDiskSecureBuild(parent)
fs, err := filesys.MakeFsOnDiskSecureBuild(root)
if err != nil {
return nil, err
}