mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +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"
|
||||
healthStatus, err := client.HealthCheck(host)
|
||||
if healthStatus != health.Unknown {
|
||||
t.Errorf("Expected %v and got %v.", health.Unknown, healthStatus)
|
||||
if healthStatus != health.Unhealthy {
|
||||
t.Errorf("Expected %v and got %v.", health.Unhealthy, healthStatus)
|
||||
}
|
||||
if err == nil {
|
||||
t.Error("Expected a non nil error")
|
||||
if err != nil {
|
||||
t.Error("Expected a nil error")
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func TestHealthChecker(t *testing.T) {
|
||||
health Status
|
||||
}{
|
||||
{http.StatusOK, Healthy},
|
||||
{statusServerEarlyShutdown, Unknown},
|
||||
{statusServerEarlyShutdown, Unhealthy},
|
||||
{http.StatusBadRequest, Unhealthy},
|
||||
{http.StatusBadGateway, Unhealthy},
|
||||
{http.StatusInternalServerError, Unhealthy},
|
||||
@ -69,7 +69,7 @@ func TestHealthChecker(t *testing.T) {
|
||||
}
|
||||
hc := NewHealthChecker()
|
||||
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)
|
||||
}
|
||||
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.
|
||||
// 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.
|
||||
// It returns Unknown and err if the HTTP communication itself fails.
|
||||
// If the HTTP response code is unsuccessful or HTTP communication fails, it returns Unhealthy.
|
||||
// This is exported because some other packages may want to do direct HTTP checks.
|
||||
func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) {
|
||||
res, err := client.Get(url)
|
||||
if err != nil {
|
||||
return Unknown, err
|
||||
glog.V(1).Infof("HTTP probe error: %v", err)
|
||||
return Unhealthy, nil
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest {
|
||||
|
Loading…
Reference in New Issue
Block a user