forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Graceful shutdown for the API server (argoproj#18642)
Closes argoproj#18642 Implements a graceful shutdown the the API server. Without this, ArgoCD API server will eventually return 502 during rolling update. However, healthcheck would return 503 if the server is terminating. Signed-off-by: Andrii Korotkov <andrii.korotkov@verkada.com> Co-authored-by: Leonardo Luz Almeida <leonardo_almeida@intuit.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
- Loading branch information
1 parent
8bce61e
commit de51fbb
Showing
4 changed files
with
258 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package e2e | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/argoproj/argo-cd/v2/test/e2e/fixture" | ||
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture" | ||
) | ||
|
||
func checkHealth(t *testing.T, requireHealthy bool) { | ||
t.Helper() | ||
resp, err := DoHttpRequest("GET", "/healthz?full=true", "") | ||
if requireHealthy { | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, resp.StatusCode) | ||
} else { | ||
if err != nil { | ||
if !strings.Contains(err.Error(), "connection refused") && !strings.Contains(err.Error(), "connection reset by peer") { | ||
require.NoErrorf(t, err, "If an error returned, it must be about connection refused or reset by peer") | ||
} | ||
} else { | ||
require.Contains(t, []int{http.StatusOK, http.StatusServiceUnavailable}, resp.StatusCode) | ||
} | ||
} | ||
} | ||
|
||
func TestAPIServerGracefulRestart(t *testing.T) { | ||
EnsureCleanState(t) | ||
|
||
// Should be healthy. | ||
checkHealth(t, true) | ||
// Should trigger API server restart. | ||
fixture.SetParamInSettingConfigMap("additionalUrls", "- http://test") | ||
|
||
// Wait for ~30 seconds | ||
for i := 0; i < 300; i++ { | ||
checkHealth(t, false) | ||
time.Sleep(100 * time.Millisecond) | ||
} | ||
// One final time, should be healthy, or restart is considered too slow. | ||
checkHealth(t, true) | ||
} |