mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-24 09:38:09 +01:00
Fix by comments
Signed-off-by: mmpei <peimingming@corp.netease.com>
This commit is contained in:
parent
4946c7bba7
commit
f32670058a
@ -72,5 +72,9 @@ func (a *adapter) PrepareForPush(resources []*model.Resource) error {
|
||||
|
||||
// HealthCheck checks health status of a registry
|
||||
func (a *adapter) HealthCheck() (model.HealthStatus, error) {
|
||||
return model.Healthy, nil
|
||||
err := a.client.checkHealthy()
|
||||
if err == nil {
|
||||
return model.Healthy, nil
|
||||
}
|
||||
return model.Unhealthy, err
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func TestPrepareForPush(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHealthCheck(t *testing.T) {
|
||||
adapter := &adapter{}
|
||||
adapter, _ := newAdapter(nil)
|
||||
status, err := adapter.HealthCheck()
|
||||
require.Equal(t, model.Healthy, string(status))
|
||||
require.Nil(t, err)
|
||||
|
@ -52,7 +52,7 @@ func (a *adapter) FetchCharts(filters []*model.Filter) ([]*model.Resource, error
|
||||
versionList, err := a.client.fetchChartDetail(repository.Name)
|
||||
if err != nil {
|
||||
log.Errorf("fetch chart detail: %v", err)
|
||||
continue
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vTags := []*adp.VTag{}
|
||||
@ -112,7 +112,7 @@ func (a *adapter) DownloadChart(name, version string) (io.ReadCloser, error) {
|
||||
return a.download(v)
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return nil, errors.New("chart not found")
|
||||
}
|
||||
|
||||
func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
|
||||
|
@ -91,6 +91,25 @@ func (c *Client) fetchChartDetail(chartName string) (*chartVersionList, error) {
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (c *Client) checkHealthy() error {
|
||||
request, err := http.NewRequest(http.MethodGet, baseURL, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
ioutil.ReadAll(resp.Body)
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
return nil
|
||||
}
|
||||
return errors.New("helm hub is unhealthy")
|
||||
}
|
||||
|
||||
// do work as a proxy of Do function from net.http
|
||||
func (c *Client) do(req *http.Request) (*http.Response, error) {
|
||||
return c.client.Do(req)
|
||||
|
Loading…
Reference in New Issue
Block a user