Merge pull request #103967 from pacoxu/probe-warning

add probe warning message body for terminated redirect
This commit is contained in:
Kubernetes Prow Robot 2022-01-06 08:57:01 -08:00 committed by GitHub
commit a18b0272e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -129,7 +129,7 @@ func DoHTTPProbe(url *url.URL, headers http.Header, client GetHTTPInterface) (pr
if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest { if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest {
if res.StatusCode >= http.StatusMultipleChoices { // Redirect if res.StatusCode >= http.StatusMultipleChoices { // Redirect
klog.V(4).Infof("Probe terminated redirects for %s, Response: %v", url.String(), *res) klog.V(4).Infof("Probe terminated redirects for %s, Response: %v", url.String(), *res)
return probe.Warning, body, nil return probe.Warning, fmt.Sprintf("Probe terminated redirects, Response body: %v", body), nil
} }
klog.V(4).Infof("Probe succeeded for %s, Response: %v", url.String(), *res) klog.V(4).Infof("Probe succeeded for %s, Response: %v", url.String(), *res)
return probe.Success, body, nil return probe.Success, body, nil

View File

@ -139,6 +139,17 @@ func TestHTTPProbeChecker(t *testing.T) {
} }
} }
redirectHandlerWithBody := func(s int, body string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
http.Redirect(w, r, "/new", s)
} else if r.URL.Path == "/new" {
w.WriteHeader(s)
w.Write([]byte(body))
}
}
}
followNonLocalRedirects := true followNonLocalRedirects := true
prober := New(followNonLocalRedirects) prober := New(followNonLocalRedirects)
testCases := []struct { testCases := []struct {
@ -336,6 +347,16 @@ func TestHTTPProbeChecker(t *testing.T) {
handler: redirectHandler(http.StatusPermanentRedirect, true), // 308 handler: redirectHandler(http.StatusPermanentRedirect, true), // 308
health: probe.Failure, health: probe.Failure,
}, },
{
handler: redirectHandlerWithBody(http.StatusPermanentRedirect, ""), // redirect with empty body
health: probe.Warning,
accBody: "Probe terminated redirects, Response body:",
},
{
handler: redirectHandlerWithBody(http.StatusPermanentRedirect, "ok body"), // redirect with body
health: probe.Warning,
accBody: "Probe terminated redirects, Response body: ok body",
},
} }
for i, test := range testCases { for i, test := range testCases {
t.Run(fmt.Sprintf("case-%2d", i), func(t *testing.T) { t.Run(fmt.Sprintf("case-%2d", i), func(t *testing.T) {

View File

@ -310,7 +310,7 @@ var _ = SIGDescribe("Probing container", func() {
"reason": events.ContainerProbeWarning, "reason": events.ContainerProbeWarning,
}.AsSelector().String() }.AsSelector().String()
framework.ExpectNoError(e2eevents.WaitTimeoutForEvent( framework.ExpectNoError(e2eevents.WaitTimeoutForEvent(
f.ClientSet, f.Namespace.Name, expectedEvent, "0.0.0.0", framework.PodEventTimeout)) f.ClientSet, f.Namespace.Name, expectedEvent, "Probe terminated redirects, Response body: <a href=\"http://0.0.0.0/\">Found</a>.", framework.PodEventTimeout))
}) })
/* /*