From 5d8d0b5554ea49233f2d0f23204f8b61abc0fde9 Mon Sep 17 00:00:00 2001 From: Sebastian Nallar Date: Fri, 26 Sep 2025 09:33:29 -0300 Subject: [PATCH] feat(agent): add configurable graceful shutdown capabilities - Add terminationGracePeriodSeconds support (configurable, defaults to 900s) - Implement preStop lifecycle hook with logging and configurable delay - Maintain backward compatibility with existing lifecycle configuration - Enable graceful shutdown by default with sensible defaults --- charts/agent/templates/deployment.yaml | 15 +++++++++++++++ charts/agent/values.yaml | 10 ++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/charts/agent/templates/deployment.yaml b/charts/agent/templates/deployment.yaml index 33b37e9..b5996e6 100644 --- a/charts/agent/templates/deployment.yaml +++ b/charts/agent/templates/deployment.yaml @@ -26,6 +26,9 @@ spec: {{- end }} spec: + {{- if .Values.gracefulShutdown.enabled }} + terminationGracePeriodSeconds: {{ .Values.gracefulShutdown.terminationGracePeriodSeconds }} + {{- end }} priorityClassName: nullplatform-critical-{{ .Release.Name }} serviceAccountName: {{ include "agent.serviceAccountName" . }} securityContext: @@ -62,8 +65,20 @@ spec: envFrom: - secretRef: name: {{ .Values.configuration.secretName }}-{{ .Release.Name }} + {{- if .Values.gracefulShutdown.enabled }} + lifecycle: + preStop: + exec: + command: + - /bin/sh + - -c + - | + echo "$(date): Initiating graceful shutdown..." >> /tmp/shutdown.log + sleep {{ .Values.gracefulShutdown.preStopDelay }} + {{- else }} lifecycle: {{- toYaml .Values.lifecycle | nindent 12 }} + {{- end }} {{- with .Values.volumes }} volumes: {{- toYaml . | nindent 8 }} diff --git a/charts/agent/values.yaml b/charts/agent/values.yaml index 0266e2a..786302c 100644 --- a/charts/agent/values.yaml +++ b/charts/agent/values.yaml @@ -5,7 +5,7 @@ namespace: nullplatform-tools args: - "--tags=$(TAGS)" - "--apikey=$(NP_API_KEY)" - - "--runtime=host" + - "--runtime=k8s" - "--command-executor-env=NP_API_KEY=$(NP_API_KEY)" - "--command-executor-debug" - "--webserver-enabled" @@ -111,7 +111,13 @@ initScripts: [] # Additional volumeMounts on the output Deployment definition. volumeMounts: [] -#Lifecycle preStop Hook for Graceful Agent Shutdown +# Graceful shutdown configuration +gracefulShutdown: + enabled: true + terminationGracePeriodSeconds: 900 + preStopDelay: 2 + +# Legacy lifecycle configuration (used when gracefulShutdown.enabled is false) lifecycle: preStop: exec: