mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Expose path to localize destination
This commit is contained in:
@@ -9,7 +9,9 @@ import (
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// Run `kustomize localize`s files referenced by kustomization target in scope to destination newDir on fSys.
|
||||
func Run(fSys filesys.FileSystem, target, scope, newDir string) error {
|
||||
return errors.Wrap(localizer.Run(target, scope, newDir, fSys))
|
||||
// Run executes `kustomize localize` on fSys given the `localize` arguments and
|
||||
// returns the path to the created newDir.
|
||||
func Run(fSys filesys.FileSystem, target, scope, newDir string) (string, error) {
|
||||
dst, err := localizer.Run(target, scope, newDir, fSys)
|
||||
return dst, errors.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -264,10 +264,11 @@ func TestWorkingDir(t *testing.T) {
|
||||
fsExpected, fsActual, wd := PrepareFs(t, []string{"target", "base"}, files)
|
||||
SetWorkingDir(t, wd.String())
|
||||
|
||||
err := localizer.Run(fsActual, "target", ".", "")
|
||||
dst, err := localizer.Run(fsActual, "target", ".", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, wd.Join("localized-target"), dst)
|
||||
|
||||
SetupDir(t, fsExpected, wd.Join("localized-target"), files)
|
||||
SetupDir(t, fsExpected, dst, files)
|
||||
CheckFs(t, wd.String(), fsExpected, fsActual)
|
||||
}
|
||||
|
||||
@@ -301,10 +302,10 @@ func TestLoaderSymlinks(t *testing.T) {
|
||||
})
|
||||
SetWorkingDir(t, testDir.String())
|
||||
|
||||
err := localizer.Run(fsActual, "target-link", "target", "")
|
||||
dst, err := localizer.Run(fsActual, "target-link", "target", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, testDir.Join("localized-target"), dst)
|
||||
|
||||
dst := testDir.Join("localized-target")
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
"kustomization.yaml": fmt.Sprintf(`resources:
|
||||
- %s
|
||||
@@ -322,10 +323,10 @@ func TestRemoteTargetDefaultDst(t *testing.T) {
|
||||
SetWorkingDir(t, testDir.String())
|
||||
|
||||
const target = simpleURL + urlQuery
|
||||
err := localizer.Run(fsActual, target, "", "")
|
||||
dst, err := localizer.Run(fsActual, target, "", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, testDir.Join("localized-simple-kustomize-v4.5.7"), dst)
|
||||
|
||||
dst := testDir.Join("localized-simple-kustomize-v4.5.7")
|
||||
_, files := simplePathAndFiles(t)
|
||||
SetupDir(t, fsExpected,
|
||||
filepath.Join(dst, "api", "krusty", "testdata", "localize", "simple"),
|
||||
@@ -364,7 +365,7 @@ func TestBadArgs(t *testing.T) {
|
||||
fsExpected, fsActual, testDir := PrepareFs(t, nil, kust)
|
||||
SetWorkingDir(t, testDir.String())
|
||||
|
||||
err := localizer.Run(fsActual, test.target, test.scope, test.dst)
|
||||
_, err := localizer.Run(fsActual, test.target, test.scope, test.dst)
|
||||
require.EqualError(t, err, test.err)
|
||||
|
||||
SetupDir(t, fsExpected, testDir.String(), kust)
|
||||
@@ -383,9 +384,10 @@ openapi:
|
||||
"kustomization.yaml": fmt.Sprintf(kustf, `https://raw.githubusercontent.com/kubernetes-sigs/kustomize/kustomize/v4.5.7/api/krusty/testdata/customschema.json`),
|
||||
})
|
||||
|
||||
dst := testDir.Join("dst")
|
||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
||||
newDir := testDir.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
localizedPath := filepath.Join(LocalizeDir, "raw.githubusercontent.com",
|
||||
"kubernetes-sigs", "kustomize", "kustomize", "v4.5.7", "api", "krusty",
|
||||
@@ -404,9 +406,10 @@ func TestRemoteRoot(t *testing.T) {
|
||||
`, simpleURL+urlQuery),
|
||||
})
|
||||
|
||||
dst := testDir.Join("dst")
|
||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
||||
newDir := testDir.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
localizedPath, files := simplePathAndFiles(t)
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
@@ -427,9 +430,10 @@ func TestNestedRemoteRoots(t *testing.T) {
|
||||
`,
|
||||
})
|
||||
|
||||
dst := testDir.Join("dst")
|
||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
||||
newDir := testDir.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
localizedPath, files := remotePathAndFiles(t)
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
@@ -450,7 +454,7 @@ func TestResourcesRepoNotFile(t *testing.T) {
|
||||
}
|
||||
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
|
||||
|
||||
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||
|
||||
fileErr := fmt.Sprintf(`invalid resource at file "%s": MalformedYAMLError`, repo)
|
||||
rootErr := fmt.Sprintf(`unable to localize root "%s": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization'`, repo)
|
||||
@@ -473,7 +477,7 @@ func TestRemoteRootNoRef(t *testing.T) {
|
||||
}
|
||||
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
|
||||
|
||||
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||
|
||||
const fileErr = "invalid file reference: URL is a git repository"
|
||||
rootErr := fmt.Sprintf(`localize remote root "%s" missing ref query string parameter`, root)
|
||||
@@ -497,7 +501,7 @@ func TestExistingCacheDir(t *testing.T) {
|
||||
}
|
||||
fsExpected, fsActual, testDir := PrepareFs(t, []string{LocalizeDir}, file)
|
||||
|
||||
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||
require.ErrorContains(t, err, fmt.Sprintf(`already contains localized-files needed to store file "%s"`, remoteFile))
|
||||
|
||||
SetupDir(t, fsExpected, testDir.String(), file)
|
||||
@@ -518,9 +522,10 @@ minecraftServer:
|
||||
filepath.Join("nested", "dirs", "home", "name"),
|
||||
}, files)
|
||||
|
||||
dst := testDir.Join("dst")
|
||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
||||
newDir := testDir.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
SetupDir(t, fsExpected, dst, files)
|
||||
CheckFs(t, dst, fsExpected, fsActual)
|
||||
@@ -553,9 +558,10 @@ helmGlobals:
|
||||
filepath.Join("target", "home-link"): "home",
|
||||
})
|
||||
|
||||
dst := scope.Join("dst")
|
||||
err := localizer.Run(fsActual, scope.Join("target"), scope.String(), dst)
|
||||
newDir := scope.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, scope.Join("target"), scope.String(), newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
filepath.Join("target", "Kustomization"): fmt.Sprintf(`helmCharts:
|
||||
@@ -592,9 +598,10 @@ helmChartInflationGenerator:
|
||||
})
|
||||
link(t, target, map[string]string{"charts": "home"})
|
||||
|
||||
dst := target.Join("dst")
|
||||
err := localizer.Run(fsActual, target.String(), "", dst)
|
||||
newDir := target.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, target.String(), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
"kustomization.yaml": `helmChartInflationGenerator:
|
||||
@@ -632,9 +639,10 @@ func TestHelmHomeEscapesScope(t *testing.T) {
|
||||
filepath.Join("target", "home", "file-link"): "file",
|
||||
})
|
||||
|
||||
dst := testDir.Join("dst")
|
||||
err := localizer.Run(fsActual, testDir.Join("target"), "", dst)
|
||||
newDir := testDir.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, testDir.Join("target"), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
"kustomization.yaml": `helmGlobals:
|
||||
@@ -661,9 +669,10 @@ func TestSymlinkedFileSource(t *testing.T) {
|
||||
"filename-used-as-key-in-configMap": "different-key",
|
||||
})
|
||||
|
||||
dst := target.Join("dst")
|
||||
err := localizer.Run(fsActual, target.String(), "", dst)
|
||||
newDir := target.Join("dst")
|
||||
dst, err := localizer.Run(fsActual, target.String(), "", newDir)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newDir, dst)
|
||||
|
||||
SetupDir(t, fsExpected, dst, map[string]string{
|
||||
"kustomization.yaml": `configMapGenerator:
|
||||
|
||||
Reference in New Issue
Block a user