From 997feec5a52d2dc80cff084831a8b3df81ec28e7 Mon Sep 17 00:00:00 2001 From: raazadarsh Date: Wed, 31 Jul 2024 17:05:04 -0400 Subject: [PATCH] fix: added graceful shutdown of envoy sidecar for job completion --- cmd/api/main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/api/main.go b/cmd/api/main.go index e5cc71c..31bb1cc 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "net/http" "os" "os/signal" "runtime" @@ -92,6 +93,24 @@ func main() { <-sigs log.Print("Received shutdown signal, shutting down the application") cancel() + + // Define the endpoint for the Istio Envoy sidecar admin interface + istioEndpoint := "http://localhost:15020/quitquitquit" + + // Create a POST request to shut down Envoy + req, err := http.NewRequest("POST", istioEndpoint, nil) + if err != nil { + log.Error().Err(err).Msg("Error creating request") + } + + // Send the request using a new client + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + log.Error().Err(err).Msg("Error sending request to Envoy:") + } + defer resp.Body.Close() + log.Info().Msgf("Envoy shutdown response status: %s", resp.Status) os.Exit(0) }()