-
Notifications
You must be signed in to change notification settings - Fork 775
Minimize downtime during Pod recycling #2233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ad0185
Minimize downtime during pod recycling
d6146ab
Add missing imports
ef6adcf
Fix PR comments
42de81f
PR comments fixes
7a420ad
Update go.sum
aef6ca0
Fix panic in ContinuousHealthCheck
3d75dc6
Add UT for .WithPreStopHook, rename parameter
b1339c2
Move waiting for LB IP provisioning to separate step
c3a533f
Use forwarding for local and svc for in cluster execution
c0ecef4
Fix conditional variable assignement
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package nodespec | ||
|
|
||
| import ( | ||
| "path" | ||
|
|
||
| "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/volume" | ||
| v1 "k8s.io/api/core/v1" | ||
| ) | ||
|
|
||
| func NewPreStopHook() *v1.Handler { | ||
| return &v1.Handler{ | ||
| Exec: &v1.ExecAction{ | ||
| Command: []string{"bash", "-c", path.Join(volume.ScriptsVolumeMountPath, PreStopHookScriptConfigKey)}}, | ||
| } | ||
| } | ||
|
|
||
| const PreStopHookScriptConfigKey = "pre-stop-hook-script.sh" | ||
| const PreStopHookScript = `#!/usr/bin/env bash | ||
|
|
||
| set -eux | ||
|
|
||
| # This script will wait for up to $MAX_WAIT_SECONDS for $POD_IP to disappear from DNS record, | ||
| # then it will wait additional $ADDITIONAL_WAIT_SECONDS and exit. This slows down the process shutdown | ||
| # and allows to make changes to the pool gracefully, without blackholing traffic when DNS | ||
| # contains IP that is already inactive. Assumes $HEADLESS_SERVICE_NAME and $POD_IP env variables are defined. | ||
|
|
||
| # max time to wait for pods IP to disappear from DNS. As this runs in parallel to grace period | ||
| # (defaulting to 30s) after which process is SIGKILLed, it should be set to allow enough time | ||
| # for the process to gracefully terminate. | ||
| MAX_WAIT_SECONDS=${MAX_WAIT_SECONDS:=20} | ||
|
|
||
| # additional wait, allows queries to successfully use IP from DNS from before pod termination | ||
| # this gives a little bit more time for clients that resolved DNS just before DNS record | ||
| # was updated. | ||
| ADDITIONAL_WAIT_SECONDS=${ADDITIONAL_WAIT_SECONDS:=1} | ||
|
|
||
| START_TIME=$(date +%s) | ||
| while true; do | ||
| ELAPSED_TIME=$(($(date +%s) - $START_TIME)) | ||
|
|
||
| if [ $ELAPSED_TIME -gt $MAX_WAIT_SECONDS ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! getent hosts $HEADLESS_SERVICE_NAME | grep $POD_IP; then | ||
| sleep $ADDITIONAL_WAIT_SECONDS | ||
| exit 0 | ||
| fi | ||
|
|
||
| sleep 1 | ||
| done | ||
| ` |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.