mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #3144 from saad-ali/3041ChangeUnhealthyStatus
Have Http Liveness Probe report "Unhealthy" on connection failure instead of "Unknown"
This commit is contained in:
commit
1a70421630
@ -131,10 +131,10 @@ func TestNewKubeletClient(t *testing.T) {
|
|||||||
|
|
||||||
host := "127.0.0.1"
|
host := "127.0.0.1"
|
||||||
healthStatus, err := client.HealthCheck(host)
|
healthStatus, err := client.HealthCheck(host)
|
||||||
if healthStatus != health.Unknown {
|
if healthStatus != health.Unhealthy {
|
||||||
t.Errorf("Expected %v and got %v.", health.Unknown, healthStatus)
|
t.Errorf("Expected %v and got %v.", health.Unhealthy, healthStatus)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Error("Expected a non nil error")
|
t.Error("Expected a nil error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func TestHealthChecker(t *testing.T) {
|
|||||||
health Status
|
health Status
|
||||||
}{
|
}{
|
||||||
{http.StatusOK, Healthy},
|
{http.StatusOK, Healthy},
|
||||||
{statusServerEarlyShutdown, Unknown},
|
{statusServerEarlyShutdown, Unhealthy},
|
||||||
{http.StatusBadRequest, Unhealthy},
|
{http.StatusBadRequest, Unhealthy},
|
||||||
{http.StatusBadGateway, Unhealthy},
|
{http.StatusBadGateway, Unhealthy},
|
||||||
{http.StatusInternalServerError, Unhealthy},
|
{http.StatusInternalServerError, Unhealthy},
|
||||||
@ -69,7 +69,7 @@ func TestHealthChecker(t *testing.T) {
|
|||||||
}
|
}
|
||||||
hc := NewHealthChecker()
|
hc := NewHealthChecker()
|
||||||
health, err := hc.HealthCheck("test", "", api.PodStatus{}, container)
|
health, err := hc.HealthCheck("test", "", api.PodStatus{}, container)
|
||||||
if err != nil && tt.health != Unknown {
|
if err != nil && tt.health != Unhealthy {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if health != tt.health {
|
if health != tt.health {
|
||||||
|
@ -88,13 +88,13 @@ func formatURL(host string, port int, path string) string {
|
|||||||
|
|
||||||
// DoHTTPCheck checks if a GET request to the url succeeds.
|
// DoHTTPCheck checks if a GET request to the url succeeds.
|
||||||
// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy.
|
// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy.
|
||||||
// If the HTTP response code is unsuccessful, it returns Unhealthy.
|
// If the HTTP response code is unsuccessful or HTTP communication fails, it returns Unhealthy.
|
||||||
// It returns Unknown and err if the HTTP communication itself fails.
|
|
||||||
// This is exported because some other packages may want to do direct HTTP checks.
|
// This is exported because some other packages may want to do direct HTTP checks.
|
||||||
func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) {
|
func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) {
|
||||||
res, err := client.Get(url)
|
res, err := client.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Unknown, err
|
glog.V(1).Infof("HTTP probe error: %v", err)
|
||||||
|
return Unhealthy, nil
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest {
|
if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest {
|
||||||
|
Loading…
Reference in New Issue
Block a user