mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Merge pull request #2169 from yujunz/loader/go-getter
Replace git cloner with go getter to support various target
This commit is contained in:
@@ -170,30 +170,49 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
|
||||
if path == "" {
|
||||
return nil, fmt.Errorf("new root cannot be empty")
|
||||
}
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(path)
|
||||
if err == nil {
|
||||
// Treat this as git repo clone request.
|
||||
|
||||
root, errD := func() (filesys.ConfirmedDir, error) {
|
||||
if filepath.IsAbs(path) {
|
||||
return "", fmt.Errorf("new root '%s' cannot be absolute", path)
|
||||
}
|
||||
root, err := demandDirectoryRoot(fl.fSys, fl.root.Join(path))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := fl.errIfGitContainmentViolation(root); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := fl.errIfArgEqualOrHigher(root); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return root, nil
|
||||
}()
|
||||
|
||||
if errD == nil {
|
||||
return newLoaderAtConfirmedDir(
|
||||
fl.loadRestrictor, root, fl.fSys, fl, fl.cloner), nil
|
||||
}
|
||||
|
||||
ldr, errL := func() (ifc.Loader, error) {
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := fl.errIfRepoCycle(repoSpec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newLoaderAtGitClone(
|
||||
repoSpec, fl.fSys, fl, fl.cloner)
|
||||
ldr, err := newLoaderAtGitClone(repoSpec, fl.fSys, fl, fl.cloner)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error create loader: %s", err)
|
||||
}
|
||||
return ldr, nil
|
||||
}()
|
||||
|
||||
if errL == nil {
|
||||
return ldr, nil
|
||||
}
|
||||
if filepath.IsAbs(path) {
|
||||
return nil, fmt.Errorf("new root '%s' cannot be absolute", path)
|
||||
}
|
||||
root, err := demandDirectoryRoot(fl.fSys, fl.root.Join(path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := fl.errIfGitContainmentViolation(root); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := fl.errIfArgEqualOrHigher(root); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newLoaderAtConfirmedDir(
|
||||
fl.loadRestrictor, root, fl.fSys, fl, fl.cloner), nil
|
||||
return nil, fmt.Errorf("cannot load at directory %q nor load at git clone %q", errD, errL)
|
||||
}
|
||||
|
||||
// newLoaderAtGitClone returns a new Loader pinned to a temporary
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
getter "github.com/yujunz/go-getter"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
"sigs.k8s.io/kustomize/api/ifc"
|
||||
"sigs.k8s.io/kustomize/api/internal/git"
|
||||
@@ -19,16 +26,43 @@ import (
|
||||
func NewLoader(
|
||||
lr LoadRestrictorFunc,
|
||||
target string, fSys filesys.FileSystem) (ifc.Loader, error) {
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(target)
|
||||
if err == nil {
|
||||
// The target qualifies as a remote git target.
|
||||
return newLoaderAtGitClone(
|
||||
repoSpec, fSys, nil, git.ClonerUsingGitExec)
|
||||
|
||||
root, errD := demandDirectoryRoot(fSys, target)
|
||||
if errD == nil {
|
||||
return newLoaderAtConfirmedDir(lr, root, fSys, nil, getRepo), nil
|
||||
}
|
||||
root, err := demandDirectoryRoot(fSys, target)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
ldr, errL := newLoaderAtGitClone(
|
||||
(&git.RepoSpec{}).WithRaw(target), fSys, nil, getRepo)
|
||||
|
||||
if errL != nil {
|
||||
return nil, fmt.Errorf("Error demand directory %q and create loader %q", errD, errL)
|
||||
}
|
||||
return newLoaderAtConfirmedDir(
|
||||
lr, root, fSys, nil, git.ClonerUsingGitExec), nil
|
||||
|
||||
return ldr, nil
|
||||
}
|
||||
|
||||
func getRepo(repoSpec *git.RepoSpec) error {
|
||||
var err error
|
||||
repoSpec.Dir, err = filesys.NewTmpConfirmedDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the pwd
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting wd: %s", err)
|
||||
}
|
||||
|
||||
opts := []getter.ClientOption{}
|
||||
client := &getter.Client{
|
||||
Ctx: context.TODO(),
|
||||
Src: repoSpec.Raw(),
|
||||
Dst: repoSpec.Dir.String(),
|
||||
Pwd: pwd,
|
||||
Mode: getter.ClientModeAny,
|
||||
Options: opts,
|
||||
}
|
||||
return client.Get()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user