-
Notifications
You must be signed in to change notification settings - Fork 522
CLOUDP-66661: Enable graceful shutdowns #105
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
11 commits
Select commit
Hold shift + click to select a range
fc987b7
Rename pre-stop hook to version upgrade post-start hook
fabianlindfors a21e626
Update Evergreen
fabianlindfors cee9022
Update hook log path
fabianlindfors 8d57c67
Fix outdated comment
fabianlindfors 38e6f75
Improve version hook log messages
fabianlindfors c2920c0
Switch from pre-stop hook to post-start hook with mongod as PID 1
fabianlindfors b107ac2
Switch to logging to stdout
fabianlindfors 160ab4a
Move version change hook from comment to architecture.md
fabianlindfors 37e8085
Remove redundant "hook" from name
fabianlindfors a947848
Fix failing unit test
fabianlindfors bb10a2d
Update outdated comment
fabianlindfors 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,14 +43,13 @@ import ( | |
|
|
||
| const ( | ||
| agentImageEnv = "AGENT_IMAGE" | ||
| preStopHookImageEnv = "PRE_STOP_HOOK_IMAGE" | ||
| versionUpgradeHookImageEnv = "VERSION_UPGRADE_HOOK_IMAGE" | ||
| agentHealthStatusFilePathEnv = "AGENT_STATUS_FILEPATH" | ||
| preStopHookLogFilePathEnv = "PRE_STOP_HOOK_LOG_PATH" | ||
|
|
||
| AutomationConfigKey = "automation-config" | ||
| agentName = "mongodb-agent" | ||
| mongodbName = "mongod" | ||
| preStopHookName = "mongod-prehook" | ||
| versionUpgradeHookName = "mongod-posthook" | ||
| dataVolumeName = "data-volume" | ||
| versionManifestFilePath = "/usr/local/version_manifest.json" | ||
| readinessProbePath = "/var/lib/mongodb-mms-automation/probes/readinessprobe" | ||
|
|
@@ -526,11 +525,11 @@ func mongodbAgentContainer(volumeMounts []corev1.VolumeMount) container.Modifica | |
| ) | ||
| } | ||
|
|
||
| func preStopHookInit(volumeMount []corev1.VolumeMount) container.Modification { | ||
| func versionUpgradeHookInit(volumeMount []corev1.VolumeMount) container.Modification { | ||
| return container.Apply( | ||
| container.WithName(preStopHookName), | ||
| container.WithCommand([]string{"cp", "pre-stop-hook", "/hooks/pre-stop-hook"}), | ||
| container.WithImage(os.Getenv(preStopHookImageEnv)), | ||
| container.WithName(versionUpgradeHookName), | ||
| container.WithCommand([]string{"cp", "version-upgrade-hook", "/hooks/version-upgrade"}), | ||
| container.WithImage(os.Getenv(versionUpgradeHookImageEnv)), | ||
| container.WithImagePullPolicy(corev1.PullAlways), | ||
| container.WithVolumeMounts(volumeMount), | ||
| ) | ||
|
|
@@ -540,15 +539,15 @@ func mongodbContainer(version string, volumeMounts []corev1.VolumeMount) contain | |
| mongoDbCommand := []string{ | ||
| "/bin/sh", | ||
| "-c", | ||
| // we execute the pre-stop hook once the mongod has been gracefully shut down by the agent. | ||
| `while [ ! -f /data/automation-mongod.conf ]; do sleep 3 ; done ; sleep 2 ; | ||
| # start mongod with this configuration | ||
| mongod -f /data/automation-mongod.conf ; | ||
| ` | ||
| # run post-start hook to handle version changes | ||
| /hooks/version-upgrade | ||
|
|
||
| # wait for config to be created by the agent | ||
| while [ ! -f /data/automation-mongod.conf ]; do sleep 3 ; done ; sleep 2 ; | ||
|
|
||
| # start the pre-stop-hook to restart the Pod when needed | ||
| # If the Pod does not require to be restarted, the pre-stop-hook will | ||
| # exit(0) for Kubernetes to restart the container. | ||
| /hooks/pre-stop-hook ; | ||
| # start mongod with this configuration | ||
| exec mongod -f /data/automation-mongod.conf ; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| `, | ||
| } | ||
|
|
||
|
|
@@ -562,10 +561,6 @@ mongod -f /data/automation-mongod.conf ; | |
| Name: agentHealthStatusFilePathEnv, | ||
| Value: "/healthstatus/agent-health-status.json", | ||
| }, | ||
| corev1.EnvVar{ | ||
| Name: preStopHookLogFilePathEnv, | ||
| Value: "/hooks/pre-stop-hook.log", | ||
| }, | ||
| ), | ||
| container.WithVolumeMounts(volumeMounts), | ||
| ) | ||
|
|
@@ -619,7 +614,7 @@ func buildStatefulSetModificationFunction(mdb mdbv1.MongoDB) statefulset.Modific | |
| podtemplatespec.WithServiceAccount(operatorServiceAccountName), | ||
| podtemplatespec.WithContainer(agentName, mongodbAgentContainer([]corev1.VolumeMount{agentHealthStatusVolumeMount, automationConfigVolumeMount, dataVolume})), | ||
| podtemplatespec.WithContainer(mongodbName, mongodbContainer(mdb.Spec.Version, []corev1.VolumeMount{mongodHealthStatusVolumeMount, dataVolume, hooksVolumeMount})), | ||
| podtemplatespec.WithInitContainer(preStopHookName, preStopHookInit([]corev1.VolumeMount{hooksVolumeMount})), | ||
| podtemplatespec.WithInitContainer(versionUpgradeHookName, versionUpgradeHookInit([]corev1.VolumeMount{hooksVolumeMount})), | ||
| buildTLSPodSpecModification(mdb), | ||
| buildScramPodSpecModification(mdb), | ||
| ), | ||
|
|
||
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.