mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #42187 from smarterclayton/wrong_error_from_timeout
Automatic merge from submit-queue (batch tested with PRs 41306, 42187, 41666, 42275, 42266) Server timeout returns an incorrect error Not a valid Status object in JSON Part of #42163
This commit is contained in:
commit
4932b1422c
@ -197,7 +197,7 @@ func (tw *baseTimeoutWriter) timeout(err *apierrors.StatusError) {
|
|||||||
if !tw.wroteHeader && !tw.hijacked {
|
if !tw.wroteHeader && !tw.hijacked {
|
||||||
tw.w.WriteHeader(http.StatusGatewayTimeout)
|
tw.w.WriteHeader(http.StatusGatewayTimeout)
|
||||||
enc := json.NewEncoder(tw.w)
|
enc := json.NewEncoder(tw.w)
|
||||||
enc.Encode(err)
|
enc.Encode(&err.ErrStatus)
|
||||||
} else {
|
} else {
|
||||||
// The timeout writer has been used by the inner handler. There is
|
// The timeout writer has been used by the inner handler. There is
|
||||||
// no way to timeout the HTTP request at the point. We have to shutdown
|
// no way to timeout the HTTP request at the point. We have to shutdown
|
||||||
|
@ -17,15 +17,18 @@ limitations under the License.
|
|||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"strings"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTimeout(t *testing.T) {
|
func TestTimeout(t *testing.T) {
|
||||||
@ -50,7 +53,7 @@ func TestTimeout(t *testing.T) {
|
|||||||
sendResponse <- struct{}{}
|
sendResponse <- struct{}{}
|
||||||
res, err := http.Get(ts.URL)
|
res, err := http.Get(ts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
t.Errorf("got res.StatusCode %d; expected %d", res.StatusCode, http.StatusOK)
|
t.Errorf("got res.StatusCode %d; expected %d", res.StatusCode, http.StatusOK)
|
||||||
@ -67,14 +70,18 @@ func TestTimeout(t *testing.T) {
|
|||||||
timeout <- time.Time{}
|
timeout <- time.Time{}
|
||||||
res, err = http.Get(ts.URL)
|
res, err = http.Get(ts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if res.StatusCode != http.StatusGatewayTimeout {
|
if res.StatusCode != http.StatusGatewayTimeout {
|
||||||
t.Errorf("got res.StatusCode %d; expected %d", res.StatusCode, http.StatusServiceUnavailable)
|
t.Errorf("got res.StatusCode %d; expected %d", res.StatusCode, http.StatusServiceUnavailable)
|
||||||
}
|
}
|
||||||
body, _ = ioutil.ReadAll(res.Body)
|
body, _ = ioutil.ReadAll(res.Body)
|
||||||
if !strings.Contains(string(body), timeoutErr.Error()) {
|
status := &metav1.Status{}
|
||||||
t.Errorf("got body %q; expected it to contain %q", string(body), timeoutErr.Error())
|
if err := json.Unmarshal(body, status); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(status, &timeoutErr.ErrStatus) {
|
||||||
|
t.Errorf("unexpected object: %s", diff.ObjectReflectDiff(&timeoutErr.ErrStatus, status))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now try to send a response
|
// Now try to send a response
|
||||||
|
2
vendor/BUILD
vendored
2
vendor/BUILD
vendored
@ -10508,7 +10508,9 @@ go_test(
|
|||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = [
|
deps = [
|
||||||
"//vendor:k8s.io/apimachinery/pkg/api/errors",
|
"//vendor:k8s.io/apimachinery/pkg/api/errors",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
"//vendor:k8s.io/apimachinery/pkg/runtime/schema",
|
||||||
|
"//vendor:k8s.io/apimachinery/pkg/util/diff",
|
||||||
"//vendor:k8s.io/apimachinery/pkg/util/sets",
|
"//vendor:k8s.io/apimachinery/pkg/util/sets",
|
||||||
"//vendor:k8s.io/apiserver/pkg/endpoints/filters",
|
"//vendor:k8s.io/apiserver/pkg/endpoints/filters",
|
||||||
"//vendor:k8s.io/apiserver/pkg/endpoints/request",
|
"//vendor:k8s.io/apiserver/pkg/endpoints/request",
|
||||||
|
Loading…
Reference in New Issue
Block a user