replication helm hub adapter bug fix

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2019-07-31 17:14:00 +08:00
parent f3ba25f656
commit b7b8332626
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
}