Skip to content

Commit

Permalink
fix: handle the process kill to not fail the pod and instead exit cle…
Browse files Browse the repository at this point in the history
…an (#527)

Signed-off-by: cpanato <ctadeu@gmail.com>

Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Jan 18, 2023
1 parent e7ab58b commit 399861b
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 if err != nil {
log.Panic(err)
}

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

0 comments on commit 399861b

Please sign in to comment.