Fix create ns failure in DockerHub (#7421)

Signed-off-by: cd1989 <chende@caicloud.io>
This commit is contained in:
De Chen 2019-04-18 18:24:28 +08:00 committed by Wang Yan
parent 15846ac524
commit c3375e4ac2
2 changed files with 2 additions and 18 deletions

View File

@ -198,7 +198,6 @@ func (a *adapter) CreateNamespace(namespace *model.Namespace) error {
// getNamespace get namespace from DockerHub, if the namespace not found, two nil would be returned.
func (a *adapter) getNamespace(namespace string) (*model.Namespace, error) {
resp, err := a.client.Do(http.MethodGet, getNamespacePath(namespace), nil)
if err != nil {
return nil, err
}
@ -214,7 +213,7 @@ func (a *adapter) getNamespace(namespace string) (*model.Namespace, error) {
}
if resp.StatusCode/100 != 2 {
log.Errorf("create namespace error: %d -- %s", resp.StatusCode, string(body))
log.Errorf("get namespace error: %d -- %s", resp.StatusCode, string(body))
return nil, fmt.Errorf("%d -- %s", resp.StatusCode, body)
}

View File

@ -97,20 +97,5 @@ func (c *Client) Do(method, path string, body io.Reader) (*http.Response, error)
}
req.Header.Set("Authorization", fmt.Sprintf("JWT %s", c.token))
resp, err := c.client.Do(req)
if err != nil {
log.Errorf("unexpected error: %v", err)
return nil, err
}
if resp.StatusCode/100 != 2 {
b, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return nil, err
}
return nil, fmt.Errorf("unexpected %d error from dockerhub: %s", resp.StatusCode, string(b))
}
return resp, nil
return c.client.Do(req)
}