Merge pull request #8594 from ywk253100/190731_replicate_chart

Fix bug in Helm Hub and Harbor adapter for replicating chart
This commit is contained in:
Wenkai Yin(尹文开) 2019-08-12 17:48:11 +08:00 committed by GitHub
commit 34f845b804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -164,6 +164,13 @@ func (a *adapter) DownloadChart(name, version string) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("failed to download the chart %s: %d %s", req.URL.String(), resp.StatusCode, string(body))
}
return resp.Body, nil
}

View File

@ -137,7 +137,7 @@ func TestDownloadChart(t *testing.T) {
},
{
Method: http.MethodGet,
Pattern: "/api/chartrepo/library/charts/harbor-1.0.tgz",
Pattern: "/chartrepo/library/charts/harbor-1.0.tgz",
Handler: func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
},

View File

@ -17,6 +17,7 @@ package helmhub
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
@ -123,7 +124,7 @@ func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
url := strings.ToLower(version.Attributes.URLs[0])
if !(strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://")) {
url = fmt.Sprintf("%s/charts/%s", version.Relationships.Chart.Data.Repo.URL, url)
url = fmt.Sprintf("%s/%s", version.Relationships.Chart.Data.Repo.URL, url)
}
req, err := http.NewRequest(http.MethodGet, url, nil)
@ -134,6 +135,13 @@ func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("failed to download the chart %s: %d %s", req.URL.String(), resp.StatusCode, string(body))
}
return resp.Body, nil
}