Skip to content
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

feat: Configure proxy container for graceful termination #425

Merged
merged 4 commits into from
Sep 19, 2023

Conversation

hessjcg
Copy link
Collaborator

@hessjcg hessjcg commented Sep 1, 2023

Add the following configuration to the workload pods so that the proxy can gracefully exit
when the main container is done.

Configure the proxy container to exit 0 when it is terminated. Send a SIGTERM to the proxy container. We want
the proxy to exit with code 0, indicating a clean termination. Without this change the proxy container would
exit with exit code 140 (meaning terminated), which would cause kubernetes to report the
pod as "exited in an error state."

Configure a workload lifecycle handler so that kubernetes calls GET /quitquitquit before terminating the proxy container.
This should give the proxy container the chance to exit gracefully before kubernetes sends a SIGTERM to the
proxy process.

Always enable the /quitquitquit proxy api.

Always set the CSQL_QUIT_URLS environment variable to a space-separated list of proxy quitquitquit urls. This way, when
the main workload container is ready to exit, it can on workload pods. When a job or cronjob's main process
is done, that container can iterate over

echo Starting job

# execute the job process
run_job

# Tell proxy containers to shut down gracefully
for url in $CSQL_QUIT_URLS ; do 
   wget --post-data '' $url
done

Fixes #361

@hessjcg hessjcg marked this pull request as ready for review September 1, 2023 16:53
@hessjcg hessjcg requested a review from a team as a code owner September 1, 2023 16:53
@hessjcg hessjcg added the tests: run Run all the tests for this PR label Sep 1, 2023
@github-actions github-actions bot removed the tests: run Run all the tests for this PR label Sep 1, 2023
@hessjcg
Copy link
Collaborator Author

hessjcg commented Sep 1, 2023

Labeled tests: run to invoke e2e tests on this PR.

Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add something to the documentation for this?

@hessjcg hessjcg mentioned this pull request Aug 14, 2023
@hessjcg
Copy link
Collaborator Author

hessjcg commented Sep 1, 2023

Yes, we need to update the docs, but I think that will be a bigger task. Issue #400 asks us to create a new doc that describes the behavior in detail. I added a requirement to describe the behavior introduced by this PR to #400.

@hessjcg
Copy link
Collaborator Author

hessjcg commented Sep 1, 2023

Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good on #400. Could we update the title? I'm not sure exactly what the scope is as written.

s.addProxyContainerEnvVar(p, "CSQL_PROXY_EXIT_ZERO_ON_SIGTERM", "true")

// Configure the pre-stop hook for /quitquitquit
c.Lifecycle = &corev1.Lifecycle{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test that verifies this behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@hessjcg hessjcg changed the title feat: Configure graceful exit 0 on proxy container termination feat: Configure proxy container for graceful termination Sep 13, 2023
@hessjcg hessjcg force-pushed the gh-361-stop-hooks branch 2 times, most recently from 55cf55b to 35e33ff Compare September 13, 2023 23:04
@@ -911,6 +915,91 @@ func TestPodTemplateAnnotations(t *testing.T) {

}

func TestQuitUrlEnvVar(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL.

Watch out for initialisms.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

csqls[2].ObjectMeta.Generation = 3

var wantQuitUrlsEnv = fmt.Sprintf(
"http://localhost:%d/quitquitquit http://localhost:%d/quitquitquit http://localhost:%d/quitquitquit", workload.DefaultAdminPort,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shorter line length is easier to read. how about this?

var wantQuitUrlsEnv = strings.Join(
  []string{
    fmt.Sprinf("http://localhost:%d/quitquitquit", workload.DefaultAdminPort),
    fmt.Sprinf("http://localhost:%d/quitquitquit", workload.DefaultAdminPort),
    fmt.Sprinf("http://localhost:%d/quitquitquit", workload.DefaultAdminPort),
  },
  " ",
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


func TestPreStopHook(t *testing.T) {

var (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var u = ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Collaborator Author

@hessjcg hessjcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated based on Eno's comments.

@@ -911,6 +915,91 @@ func TestPodTemplateAnnotations(t *testing.T) {

}

func TestQuitUrlEnvVar(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

csqls[2].ObjectMeta.Generation = 3

var wantQuitUrlsEnv = fmt.Sprintf(
"http://localhost:%d/quitquitquit http://localhost:%d/quitquitquit http://localhost:%d/quitquitquit", workload.DefaultAdminPort,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


func TestPreStopHook(t *testing.T) {

var (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

We need to pin the next release of the proxy before we can merge this, right?

@hessjcg
Copy link
Collaborator Author

hessjcg commented Sep 18, 2023

No, this will work with the current proxy version and represents a significant improvement on the operator behavior.

It will work even better when the proxy is released with PR# 1947

We can merge this PR as-is. And then when the proxy is released, we will update the default proxy image version in a separate PR.

@hessjcg hessjcg merged commit 0e0bb40 into main Sep 19, 2023
8 checks passed
@hessjcg hessjcg deleted the gh-361-stop-hooks branch September 19, 2023 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: always configure pre-stop hook to call /quitquitquit
2 participants