Skip to content

Commit 78bd452

Browse files
committed
chore: change to fail health check right after getting sigterm signal
Signed-off-by: Alessandro Yuichi Okimoto <yuichijpn@gmail.com>
1 parent ca41162 commit 78bd452

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

manifests/bucketeer/charts/api/templates/deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,11 @@ spec:
185185
- -c
186186
- |
187187
admin_port={{ .Values.envoy.adminPort }}
188-
# Wait for load balancer propagation (must match app container propagation delay)
189-
sleep 15
190188
wget -q -T 1 -O- --method=POST --body-data='' \
191189
"http://localhost:${admin_port}/drain_listeners?graceful" || true
190+
191+
# Wait for load balancer propagation (must match app container propagation delay)
192+
sleep 15
192193
exit 0
193194
command: ["envoy"]
194195
args:

manifests/bucketeer/charts/batch/templates/deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,11 @@ spec:
223223
- -c
224224
- |
225225
admin_port={{ .Values.envoy.adminPort }}
226-
# Wait for load balancer propagation (must match app container propagation delay)
227-
sleep 15
228226
wget -q -T 1 -O- --method=POST --body-data='' \
229227
"http://localhost:${admin_port}/drain_listeners?graceful" || true
228+
229+
# Wait for load balancer propagation (must match app container propagation delay)
230+
sleep 15
230231
exit 0
231232
command: ["envoy"]
232233
args:

manifests/bucketeer/charts/subscriber/templates/deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,11 @@ spec:
205205
- -c
206206
- |
207207
admin_port={{ .Values.envoy.adminPort }}
208-
# Wait for load balancer propagation (must match app container propagation delay)
209-
sleep 15
210208
wget -q -T 1 -O- --method=POST --body-data='' \
211209
"http://localhost:${admin_port}/drain_listeners?graceful" || true
210+
211+
# Wait for load balancer propagation (must match app container propagation delay)
212+
sleep 15
212213
exit 0
213214
command: ["envoy"]
214215
args:

manifests/bucketeer/charts/web/templates/deployment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,11 @@ spec:
273273
- -c
274274
- |
275275
admin_port={{ .Values.envoy.adminPort }}
276-
# Wait for load balancer propagation (must match app container propagation delay)
277-
sleep 15
278276
wget -q -T 1 -O- --method=POST --body-data='' \
279277
"http://localhost:${admin_port}/drain_listeners?graceful" || true
278+
279+
# Wait for load balancer propagation (must match app container propagation delay)
280+
sleep 15
280281
exit 0
281282
command: ["envoy"]
282283
args:

pkg/api/cmd/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,16 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
567567
defer func() {
568568
shutdownStartTime := time.Now()
569569

570-
// Wait for K8s endpoint propagation
571-
// This prevents "context deadline exceeded" errors during high traffic.
572-
time.Sleep(propagationDelay)
573-
574570
// Mark as unhealthy so readiness probes fail
575571
// This ensures Kubernetes readiness probe fails on next check,
576572
// preventing new traffic from being routed to this pod.
577573
healthChecker.Stop()
578574
restHealthChecker.Stop()
579575

576+
// Wait for K8s endpoint propagation
577+
// This prevents "context deadline exceeded" errors during high traffic.
578+
time.Sleep(propagationDelay)
579+
580580
// Shutdown order matters due to dependencies:
581581
// 1. apiGateway/httpServer make gRPC calls to the backend server
582582
// 2. We MUST drain them BEFORE stopping the backend sever

pkg/batch/cmd/server/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,15 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
632632
defer func() {
633633
shutdownStartTime := time.Now()
634634

635-
// Wait for K8s endpoint propagation
636-
// This prevents "context deadline exceeded" errors during high traffic.
637-
time.Sleep(propagationDelay)
638-
639635
// Mark as unhealthy so readiness probes fail
640636
// This ensures Kubernetes readiness probe fails on next check,
641637
// preventing new traffic from being routed to this pod.
642638
healthChecker.Stop()
643639

640+
// Wait for K8s endpoint propagation
641+
// This prevents "context deadline exceeded" errors during high traffic.
642+
time.Sleep(propagationDelay)
643+
644644
// Gracefully stop gRPC Gateway (calls the gRPC server internally)
645645
batchGateway.Stop(serverShutDownTimeout)
646646

pkg/web/cmd/server/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,16 +861,16 @@ func (s *server) Run(ctx context.Context, metrics metrics.Metrics, logger *zap.L
861861
defer func() {
862862
shutdownStartTime := time.Now()
863863

864-
// Wait for K8s endpoint propagation
865-
// This prevents "context deadline exceeded" errors during high traffic.
866-
time.Sleep(propagationDelay)
867-
868864
// Mark as unhealthy so readiness probes fail
869865
// This ensures Kubernetes readiness probe fails on next check,
870866
// preventing new traffic from being routed to this pod.
871867
healthcheckServer.Stop(5 * time.Second)
872868
restHealthChecker.Stop()
873869

870+
// Wait for K8s endpoint propagation
871+
// This prevents "context deadline exceeded" errors during high traffic.
872+
time.Sleep(propagationDelay)
873+
874874
// Stop REST servers in parallel (these call gRPC servers internally)
875875
// Stop these first to drain REST traffic before stopping gRPC
876876
var restWg sync.WaitGroup

0 commit comments

Comments
 (0)