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

fix: handle the process kill to not fail the pod and instead exit clean #527

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cmd/cloudsqlproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"log"
"os"
"os/exec"
"strings"

"chainguard.dev/exitdir"
"knative.dev/pkg/signals"
Expand All @@ -29,15 +30,18 @@ func main() {
// Leverage exitdir to use file based lifecycle management.
ctx := exitdir.Aware(signals.NewContext())

log.Printf("Starting the cloud sql proxy")
log.Println("Starting the cloud sql proxy...")
cmd := exec.CommandContext(ctx, "/cloud_sql_proxy", os.Args[1:]...) //nolint: gosec
cmd.Env = os.Environ()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
err := cmd.Run()
if err != nil && strings.Contains(err.Error(), "signal: killed") {
log.Println("Got signal to shutdown")
} else if err != nil {
log.Panic(err)
}

<-ctx.Done()
log.Println("Exiting")
log.Println("Exiting cloud sql proxy...")
}