Implement localizeFile() skeleton for patches (#4865)

* Implement localizeFile()

* Fix lint

* Address code review feedback

* Remove unnecessary String(), Error() with string formatters
* Remove processing of un-implemented methods
* Improve readability

* Remove unimplemented addLocalizeDir, hitsLocalizeDir

* Improve documentation

* Remove deprecated patchesJson6902 logic
This commit is contained in:
Anna Song
2022-11-16 10:24:48 -08:00
committed by GitHub
parent c0840b6804
commit 314b8fbefa
4 changed files with 288 additions and 38 deletions

View File

@@ -14,7 +14,13 @@ import (
"sigs.k8s.io/kustomize/kyaml/filesys"
)
// establishScope returns the effective scope given localize arguments and targetLdr at rawTarget. For remote targetArg,
// DstPrefix prefixes the target and ref, if target is remote, in the default localize destination directory name
const DstPrefix = "localized"
// LocalizeDir is the name of the localize directories used to store remote content in the localize destination
const LocalizeDir = "localized-files"
// establishScope returns the effective scope given localize arguments and targetLdr at rawTarget. For remote rawTarget,
// the effective scope is the downloaded repo.
func establishScope(rawScope string, rawTarget string, targetLdr ifc.Loader, fSys filesys.FileSystem) (filesys.ConfirmedDir, error) {
if repo := targetLdr.Repo(); repo != "" {
@@ -54,7 +60,7 @@ func createNewDir(rawNewDir string, targetLdr ifc.Loader, spec *git.RepoSpec, fS
newDir, err := filesys.ConfirmDir(fSys, rawNewDir)
if err != nil {
if errCleanup := fSys.RemoveAll(newDir.String()); errCleanup != nil {
log.Printf("%s", errors.WrapPrefixf(errCleanup, "unable to clean localize destination").Error())
log.Printf("%s", errors.WrapPrefixf(errCleanup, "unable to clean localize destination"))
}
return "", errors.WrapPrefixf(err, "unable to establish localize destination")
}
@@ -95,7 +101,27 @@ func urlBase(url string) string {
func hasRef(repoURL string) bool {
repoSpec, err := git.NewRepoSpecFromURL(repoURL)
if err != nil {
log.Fatalf("unable to parse validated root url: %s", err.Error())
log.Fatalf("unable to parse validated root url: %s", err)
}
return repoSpec.Ref != ""
}
// cleanFilePath returns file cleaned, where file is a relative path to root on fSys
func cleanFilePath(fSys filesys.FileSystem, root filesys.ConfirmedDir, file string) string {
abs := root.Join(file)
dir, f, err := fSys.CleanedAbs(abs)
if err != nil {
log.Fatalf("cannot clean validated file path %q: %s", abs, err)
}
locPath, err := filepath.Rel(root.String(), dir.Join(f))
if err != nil {
log.Fatalf("cannot find path from parent %q to file %q: %s", root, dir.Join(f), err)
}
return locPath
}
// locFilePath returns the relative localized path of validated file url fileURL
// TODO(annasong): implement
func locFilePath(_ string) string {
return filepath.Join(LocalizeDir, "")
}