mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Instead of apiserver panic when proxy a request to a dead minion,
print out proper message through http.Response
This commit is contained in:
parent
37e5f96074
commit
8e9864e8fc
@ -231,6 +231,15 @@ type minionTransport struct{}
|
|||||||
func (t *minionTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t *minionTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
resp, err := http.DefaultTransport.RoundTrip(req)
|
resp, err := http.DefaultTransport.RoundTrip(req)
|
||||||
|
|
||||||
|
if err != nil && strings.Contains(err.Error(), "connection refused") {
|
||||||
|
message := fmt.Sprintf("Failed to connect to minion:%s", req.URL.Host)
|
||||||
|
resp = &http.Response{
|
||||||
|
StatusCode: http.StatusServiceUnavailable,
|
||||||
|
Body: ioutil.NopCloser(strings.NewReader(message)),
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
if strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
|
if strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
|
||||||
// Do nothing, simply pass through
|
// Do nothing, simply pass through
|
||||||
return resp, err
|
return resp, err
|
||||||
|
Loading…
Reference in New Issue
Block a user