mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Revert "Load and calculate Destination of files for kustomize localize (#4652)"
This reverts commit bf17fe1d8f.
This commit is contained in:
@@ -18,13 +18,6 @@ import (
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
)
|
||||
|
||||
// HasRemoteFileScheme returns whether path has a url scheme that kustomize allows for
|
||||
// remote files. See https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md
|
||||
func HasRemoteFileScheme(path string) bool {
|
||||
u, err := url.Parse(path)
|
||||
return err == nil && (u.Scheme == "http" || u.Scheme == "https")
|
||||
}
|
||||
|
||||
// fileLoader is a kustomization's interface to files.
|
||||
//
|
||||
// The directory in which a kustomization file sits
|
||||
@@ -121,15 +114,6 @@ func NewFileLoaderAtRoot(fSys filesys.FileSystem) *fileLoader {
|
||||
RestrictionRootOnly, fSys, filesys.Separator)
|
||||
}
|
||||
|
||||
// Repo returns the absolute path to the repo that contains Root and true
|
||||
// if this fileLoader was created from a url; otherwise, the empty string and false
|
||||
func (fl *fileLoader) Repo() (string, bool) {
|
||||
if fl.repoSpec != nil {
|
||||
return fl.repoSpec.Dir.String(), true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Root returns the absolute path that is prepended to any
|
||||
// relative paths used in Load.
|
||||
func (fl *fileLoader) Root() string {
|
||||
@@ -295,37 +279,34 @@ func (fl *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
|
||||
return fl.referrer.errIfRepoCycle(newRepoSpec)
|
||||
}
|
||||
|
||||
func loadURL(hc *http.Client, path string) ([]byte, error) {
|
||||
resp, err := hc.Get(path)
|
||||
if err != nil {
|
||||
return nil, errors.WrapPrefixf(err, "cannot GET url")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
if _, err = git.NewRepoSpecFromURL(path); err == nil {
|
||||
return nil, errors.Errorf("URL is a git repository")
|
||||
}
|
||||
return nil, fmt.Errorf("%w: status code %d (%s)", ErrHTTP, resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.WrapPrefixf(err, "cannot read url content")
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
// Load returns the content of file at the given path,
|
||||
// else an error. Relative paths are taken relative
|
||||
// to the root.
|
||||
func (fl *fileLoader) Load(path string) ([]byte, error) {
|
||||
if HasRemoteFileScheme(path) {
|
||||
if u, err := url.Parse(path); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
|
||||
var hc *http.Client
|
||||
if fl.http != nil {
|
||||
hc = fl.http
|
||||
} else {
|
||||
hc = &http.Client{}
|
||||
}
|
||||
return loadURL(hc, path)
|
||||
resp, err := hc.Get(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
_, err := git.NewRepoSpecFromURL(path)
|
||||
if err == nil {
|
||||
return nil, errors.Errorf("URL is a git repository")
|
||||
}
|
||||
return nil, fmt.Errorf("%w: status code %d (%s)", ErrHTTP, resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
if !filepath.IsAbs(path) {
|
||||
path = fl.root.Join(path)
|
||||
|
||||
Reference in New Issue
Block a user