Skip to content

feat(graceful-shutdown): allow replacing the preStop hook from the CR - #90

Open
Anton0C wants to merge 1 commit into
ProxySQL:mainfrom
Anton0C:nmi/graceful-shutdown-preStop-override
Open

feat(graceful-shutdown): allow replacing the preStop hook from the CR#90
Anton0C wants to merge 1 commit into
ProxySQL:mainfrom
Anton0C:nmi/graceful-shutdown-preStop-override

Conversation

@Anton0C

@Anton0C Anton0C commented Aug 20, 2026

Copy link
Copy Markdown

spec.gracefulShutdown.preStop is a full corev1.LifecycleHandler. When set it replaces the built-in PROXYSQL PAUSE drain command wholesale; when unset the operator keeps the existing hook. MYSQL_PWD is still injected from the admin Secret so a custom exec can talk to admin :6032.

Without a delay, kube-proxy can still DNAT new connections after PAUSE:

client -> Service -> terminating pod (listener already paused)

With a custom preStop, wait first, then pause:

t=0  sleep N  (pod still accepts; endpoints drain)
t=N  PROXYSQL PAUSE

Example:

  gracefulShutdown:
    enabled: true
    drainTimeoutSeconds: 600
    preStop:
      exec:
        command:
          - /bin/sh
          - -c - sleep 5; mysql --no-defaults --connect-timeout=2 -h127.0.0.1 -P6032 -uadmin -e 'PROXYSQL PAUSE' 2>/dev/null || true; for i in $(seq 1 600); do c=$(mysql --no-defaults --connect-timeout=2 -N -h127.0.0.1 -P6032 -uadmin -e "SELECT Variable_Value FROM stats_mysql_global WHERE Variable_Name='Client_Connections_connected'" 2>/dev/null); [ "${c:-0}" -le 0 ] && break; sleep 1; done 

spec.gracefulShutdown.preStop is a full corev1.LifecycleHandler. When set
it replaces the built-in PROXYSQL PAUSE drain command wholesale; when
unset the operator keeps the existing hook. MYSQL_PWD is still injected
from the admin Secret so a custom exec can talk to admin :6032.

  Without a delay, kube-proxy can still DNAT new connections after PAUSE:

    client -> Service -> terminating pod (listener already paused)

  With a custom preStop, wait first, then pause:

    t=0  sleep N  (pod still accepts; endpoints drain)
    t=N  PROXYSQL PAUSE

Example:

  gracefulShutdown:
    enabled: true
    drainTimeoutSeconds: 600
    preStop:
      exec:
        command:
          - /bin/sh
          - -c
          - sleep 5; mysql --no-defaults --connect-timeout=2 -h127.0.0.1 -P6032 -uadmin -e 'PROXYSQL PAUSE' 2>/dev/null || true; for i in $(seq 1 600); do c=$(mysql --no-defaults --connect-timeout=2 -N -h127.0.0.1 -P6032 -uadmin -e "SELECT Variable_Value FROM stats_mysql_global WHERE Variable_Name='Client_Connections_connected'" 2>/dev/null); [ "${c:-0}" -le 0 ] && break; sleep 1; done
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: c5077f3e-76b9-4f9b-8636-da2a23ab8c5e


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant