mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-05 03:06:23 +00:00
Merge pull request #126265 from tnqn/fix-watch-error
Enrich the error returned from Request.Watch method Kubernetes-commit: fd58143ed2569c7eb86f46649803d1d13abc9583
This commit is contained in:
commit
d50e2a9641
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
||||
golang.org/x/time v0.3.0
|
||||
google.golang.org/protobuf v1.34.2
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0
|
||||
k8s.io/api v0.0.0-20240827233010-7ac1f767816d
|
||||
k8s.io/api v0.0.0-20240829232531-2ab66df9c902
|
||||
k8s.io/apimachinery v0.0.0-20240827232741-2465dc5239ab
|
||||
k8s.io/klog/v2 v2.130.1
|
||||
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2
|
||||
|
4
go.sum
4
go.sum
@ -157,8 +157,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/api v0.0.0-20240827233010-7ac1f767816d h1:fX+A6LC046R7PukhvXP7oFktRUm5jfnTFWhQdIDsrDs=
|
||||
k8s.io/api v0.0.0-20240827233010-7ac1f767816d/go.mod h1:ripUAtqwG9GJ/8+oGJ64+WUGoZ06zX0O8M6PVyCFA3k=
|
||||
k8s.io/api v0.0.0-20240829232531-2ab66df9c902 h1:MxDGdK5UeyIC0AO5bxZbVYUg9b7BbXgLdbs6hfrkjTc=
|
||||
k8s.io/api v0.0.0-20240829232531-2ab66df9c902/go.mod h1:ripUAtqwG9GJ/8+oGJ64+WUGoZ06zX0O8M6PVyCFA3k=
|
||||
k8s.io/apimachinery v0.0.0-20240827232741-2465dc5239ab h1:Q5sDIA+AALw+7kUA1B/eF3yOJ85ODdIe01A1TNT2t28=
|
||||
k8s.io/apimachinery v0.0.0-20240827232741-2465dc5239ab/go.mod h1:ICcwUwxYZmFXLu9oug48MqosXwccA+UCIOOtZRgdQX0=
|
||||
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
||||
|
@ -752,8 +752,9 @@ func (r *Request) Watch(ctx context.Context) (watch.Interface, error) {
|
||||
// the server must have sent us an error in 'err'
|
||||
return true, nil
|
||||
}
|
||||
if result := r.transformResponse(resp, req); result.err != nil {
|
||||
return true, result.err
|
||||
result := r.transformResponse(resp, req)
|
||||
if err := result.Error(); err != nil {
|
||||
return true, err
|
||||
}
|
||||
return true, fmt.Errorf("for request %s, got status: %v", url, resp.StatusCode)
|
||||
}()
|
||||
|
@ -977,7 +977,7 @@ func TestRequestWatch(t *testing.T) {
|
||||
Err: true,
|
||||
},
|
||||
{
|
||||
name: "server returns forbidden",
|
||||
name: "server returns forbidden with json content",
|
||||
Request: &Request{
|
||||
c: &RESTClient{
|
||||
content: defaultContentConfig(),
|
||||
@ -986,41 +986,27 @@ func TestRequestWatch(t *testing.T) {
|
||||
},
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
StatusCode: http.StatusForbidden,
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Message: "secrets is forbidden",
|
||||
Reason: metav1.StatusReasonForbidden,
|
||||
Code: http.StatusForbidden,
|
||||
})))),
|
||||
}, err: nil},
|
||||
},
|
||||
attemptsExpected: 1,
|
||||
Expect: []watch.Event{
|
||||
{
|
||||
Type: watch.Error,
|
||||
Object: &metav1.Status{
|
||||
Status: "Failure",
|
||||
Code: 500,
|
||||
Reason: "InternalError",
|
||||
Message: `an error on the server ("unable to decode an event from the watch stream: test error") has prevented the request from succeeding`,
|
||||
Details: &metav1.StatusDetails{
|
||||
Causes: []metav1.StatusCause{
|
||||
{
|
||||
Type: "UnexpectedServerResponse",
|
||||
Message: "unable to decode an event from the watch stream: test error",
|
||||
},
|
||||
{
|
||||
Type: "ClientWatchDecoding",
|
||||
Message: "unable to decode an event from the watch stream: test error",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Err: true,
|
||||
Err: true,
|
||||
ErrFn: func(err error) bool {
|
||||
if err.Error() != "secrets is forbidden" {
|
||||
return false
|
||||
}
|
||||
return apierrors.IsForbidden(err)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "server returns forbidden",
|
||||
name: "server returns forbidden without content",
|
||||
Request: &Request{
|
||||
c: &RESTClient{
|
||||
content: defaultContentConfig(),
|
||||
|
Loading…
Reference in New Issue
Block a user