Skip to content

Commit

Permalink
fix: handle the process kill to not fail the pod and instead exit clean
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Jan 18, 2023
1 parent cd52efd commit 48ea2e6
Showing 1 changed file with 7 additions and 3 deletions.
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 {
log.Panic(err)
}

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

0 comments on commit 48ea2e6

Please sign in to comment.