Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPExtender: should close resp.Body even when StatusCode not ok #48335

Merged
merged 1 commit into from Jul 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions plugin/pkg/scheduler/core/extender.go
Expand Up @@ -20,8 +20,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"

"k8s.io/api/core/v1"
Expand Down Expand Up @@ -229,7 +229,7 @@ func (h *HTTPExtender) send(action string, args interface{}, result interface{})
return err
}

url := h.extenderURL + "/" + action
url := strings.TrimRight(h.extenderURL, "/") + "/" + action

req, err := http.NewRequest("POST", url, bytes.NewReader(out))
if err != nil {
Expand All @@ -242,19 +242,11 @@ func (h *HTTPExtender) send(action string, args interface{}, result interface{})
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Failed %v with extender at URL %v, code %v", action, h.extenderURL, resp.StatusCode)
}

defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}

if err := json.Unmarshal(body, result); err != nil {
return err
}
return nil
return json.NewDecoder(resp.Body).Decode(result)
}