Created
February 19, 2020 07:04
-
-
Save devgrok/c1b3941580727a0874c40e26c1126f24 to your computer and use it in GitHub Desktop.
fix 'unsupported protocol scheme "git"' in latest Kfctl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: kfctl/pkg/kfconfig/types.go | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- kfctl/pkg/kfconfig/types.go (revision 94c35cfa53235961a329cefd144ecf524fe5cea4) | |
+++ kfctl/pkg/kfconfig/types.go (date 1582095567552) | |
@@ -11,9 +11,11 @@ | |
"os" | |
"path" | |
"path/filepath" | |
+ "regexp" | |
"strings" | |
"github.com/ghodss/yaml" | |
+ gogetter "github.com/hashicorp/go-getter" | |
"github.com/hashicorp/go-getter/helper/url" | |
kfapis "github.com/kubeflow/kfctl/v3/pkg/apis" | |
"github.com/otiai10/copy" | |
@@ -491,38 +493,53 @@ | |
} | |
log.Infof("Fetching %v to %v", r.URI, cacheDir) | |
- if err := os.MkdirAll(cacheDir, os.ModePerm); err != nil { | |
- log.Errorf("Could not create dir %v; error %v", cacheDir, err) | |
- return errors.WithStack(err) | |
- } | |
+ | |
+ fu, err := gogetter.Detect(r.URI, "", gogetter.Detectors) | |
+ // from gogetter.getForcedGetter | |
+ var forcedRegexp = regexp.MustCompile(`^([A-Za-z0-9]+)::(.+)$`) | |
+ // uri is in go-getter format (i.e. not http, may also handle local) | |
+ if ms := forcedRegexp.FindStringSubmatch(fu); ms != nil { | |
+ tarballUrlErr := gogetter.GetAny(cacheDir, fu) | |
+ if tarballUrlErr != nil { | |
+ return &kfapis.KfError{ | |
+ Code: int(kfapis.INVALID_ARGUMENT), | |
+ Message: fmt.Sprintf("couldn't download URI %v Error %v", fu, tarballUrlErr), | |
+ } | |
+ } | |
+ } else { | |
+ if err := os.MkdirAll(cacheDir, os.ModePerm); err != nil { | |
+ log.Errorf("Could not create dir %v; error %v", cacheDir, err) | |
+ return errors.WithStack(err) | |
+ } | |
- // Manifests are local dir | |
- if fi, err := os.Stat(r.URI); err == nil && fi.Mode().IsDir() { | |
- if err := copy.Copy(r.URI, cacheDir); err != nil { | |
- return errors.WithStack(err) | |
- } | |
- } else { | |
- t := &http.Transport{} | |
- t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/"))) | |
- t.RegisterProtocol("", http.NewFileTransport(http.Dir("/"))) | |
- hclient := &http.Client{Transport: t} | |
- resp, err := hclient.Get(r.URI) | |
- if err != nil { | |
- return &kfapis.KfError{ | |
- Code: int(kfapis.INVALID_ARGUMENT), | |
- Message: fmt.Sprintf("couldn't download URI %v Error %v", r.URI, err), | |
- } | |
- } | |
- defer resp.Body.Close() | |
+ // Manifests are local dir | |
+ if fi, err := os.Stat(r.URI); err == nil && fi.Mode().IsDir() { | |
+ if err := copy.Copy(r.URI, cacheDir); err != nil { | |
+ return errors.WithStack(err) | |
+ } | |
+ } else { | |
+ t := &http.Transport{} | |
+ t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/"))) | |
+ t.RegisterProtocol("", http.NewFileTransport(http.Dir("/"))) | |
+ hclient := &http.Client{Transport: t} | |
+ resp, err := hclient.Get(r.URI) | |
+ if err != nil { | |
+ return &kfapis.KfError{ | |
+ Code: int(kfapis.INVALID_ARGUMENT), | |
+ Message: fmt.Sprintf("couldn't download URI %v Error %v", r.URI, err), | |
+ } | |
+ } | |
+ defer resp.Body.Close() | |
- body, err := ioutil.ReadAll(resp.Body) | |
- if err != nil { | |
- log.Errorf("Could not read response body; error %v", err) | |
- return errors.WithStack(err) | |
- } | |
- if err := untar(body, cacheDir); err != nil { | |
- log.Errorf("Could not untar file %v; error %v", r.URI, err) | |
- return errors.WithStack(err) | |
+ body, err := ioutil.ReadAll(resp.Body) | |
+ if err != nil { | |
+ log.Errorf("Could not read response body; error %v", err) | |
+ return errors.WithStack(err) | |
+ } | |
+ if err := untar(body, cacheDir); err != nil { | |
+ log.Errorf("Could not untar file %v; error %v", r.URI, err) | |
+ return errors.WithStack(err) | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment