Skip to content

feat(sidecar-injector): add a TCP liveness probe to the gateway container - #526

Open
hossain-rayhan wants to merge 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/gateway-liveness-probe
Open

hossain-rayhan wants to merge 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/gateway-liveness-probe

Conversation

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

Summary

Adds a TCP liveness probe to the injected documentdb-gateway container. Today the container has no probes at all, so a gateway that stops accepting connections is never restarted. This is the gateway-probe part of #475, split out so it can ship on its own; #475 keeps the OTel metrics work. Addresses part of #522.

Setting Value Why
Handler tcpSocket on gatewayPort (10260 by default) Works with any gateway image, TLS on or off
initialDelaySeconds 600 The gateway entrypoint waits up to 600 s for PostgreSQL before it listens
periodSeconds / timeoutSeconds / failureThreshold 10 / 5 / 6 Restarts the gateway after about a minute without accepting connections
Readiness / startup probe none Pod readiness covers every container, so either probe would remove PostgreSQL from the CNPG Services while the gateway isn't listening and break replication

A failed probe restarts only the gateway container: PostgreSQL keeps running and no failover occurs.

Limitations (documented)

Changes

  • sidecar-injector/internal/lifecycle: gatewayLivenessProbe(port) added to the gateway container. Unit tests cover the default port and a custom gatewayPort, and check there is no readiness or startup probe; they fail without the probe.
  • test/e2e/tests/resources/sidecar_resources_test.go: asserts the probe on a real pod.
  • Docs: a Gateway Container Restarts section in the local HA guide, gatewayPort notes in the plugin guide and the product-neutral-core design, and a CHANGELOG entry.

Upgrade behavior

The plugin mutates pods only when they're created, so existing pods get the probe at their next recreation (for example a rolling restart). Upgrading the operator doesn't restart clusters.

Testing

  • go vet and go test ./... pass for the sidecar injector; go vet passes for the E2E resources package. mkdocs build --strict passes.
  • Kind (Kubernetes 1.35, published operator 1.2.1 plus this branch's sidecar image):
    • A cluster created before the plugin upgrade wasn't restarted and has no probe.
    • A cluster created afterwards has exactly the probe above, and no readiness or startup probe.
    • After running past the 600 s initial delay against the real TLS gateway: 0 gateway restarts, 0 probe-failure events, cluster healthy, reads and writes work.

…iner

Split from documentdb#475 so the gateway probe can ship on its own. The injected
documentdb-gateway container had no probes, so a gateway that stopped
accepting connections was never restarted (documentdb#522).

- tcpSocket liveness probe on gatewayPort: initial delay 600 s (the
  entrypoint waits up to 600 s for PostgreSQL), period 10 s, timeout 5 s,
  failure threshold 6. A failure restarts only the gateway container.
- No readiness or startup probe: either would make the pod unready and
  remove PostgreSQL from the CNPG Services while the gateway isn't
  listening.
- Unit tests (default and custom port, no readiness/startup probe) and
  an E2E assertion in the sidecar resources spec.
- Docs: Gateway Container Restarts in the local HA guide, including the
  limits of a TCP probe and its ERROR log lines; gatewayPort notes in the
  plugin guide and product-neutral-core design; CHANGELOG.

A request-level health check needs the gateway itself:
documentdb/documentdb#834.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 9f1a71b4-9969-4456-9f65-8d19dd550d8e
Signed-off-by: Rayhan Hossain <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the gateway TCP liveness probe change.

No open issues 🎉

What changed in this PR

Adds a TCP liveness probe to the injected gateway container so Kubernetes can restart a gateway that stops accepting connections. This delivers the gateway-probe portion of #475 and partially addresses #522.

Changes:

  • Probes the configured gateway port after a 10-minute startup grace period, without adding readiness or startup probes.
  • Adds unit and end-to-end assertions for the probe configuration.
  • Documents restart behavior, TCP health-check limitations, probe-related logging, and rollout to newly created pods.
File Description
test/​e2e/​tests/​resources/​sidecar_resources_test.go Checks gateway probes on a deployed pod.
operator/​cnpg-plugins/​sidecar-injector/​internal/​lifecycle/​lifecycle.go Adds the TCP liveness probe to the gateway container.
operator/​cnpg-plugins/​sidecar-injector/​internal/​lifecycle/​lifecycle_test.go Tests default and custom ports, timing, and absent readiness/startup probes.
docs/​operator-public-documentation/​v1/​high-availability/​local-ha.md Explains gateway restarts and probe limitations.
docs/​developer-guides/​sidecar-injector-plugin-configuration.md Notes that liveness checks use gatewayPort.
docs/​designs/​product-neutral-core.md Documents the gateway listener port requirement.
CHANGELOG.md Records the probe behavior and rollout details.

Review effort: Balanced

@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: documentation, test
Project fields suggested: Component docs · Priority P2 · Effort L · Status Needs Review
Confidence: 0.95 (deterministic)

Reasoning

component from path globs (docs, test); effort from diff stats (115+2 LOC, 7 files)

If a label is wrong, ping @patty-chow so the rules can be tuned. Issues with component labels are left alone; PR component labels are reconciled from changed paths on every run.

This branch has not been deployed

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

Labels

documentation Improvements or additions to documentation test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants