Skip to content

Add preStop lifecycle hook to postgres pod to prevent crash-loop afte…#1726

Open
sriroopar wants to merge 1 commit into
openshift:mainfrom
sriroopar:postgres-availability-fix
Open

Add preStop lifecycle hook to postgres pod to prevent crash-loop afte…#1726
sriroopar wants to merge 1 commit into
openshift:mainfrom
sriroopar:postgres-availability-fix

Conversation

@sriroopar

@sriroopar sriroopar commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

…r unclean shutdown

Description

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up dependent library

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved PostgreSQL pod shutdown behavior with graceful termination handling. Containers now execute cleanup procedures during shutdown and have a 60-second grace period to complete safely.
  • Tests

    • Extended test coverage for PostgreSQL deployment shutdown behavior and termination configuration validation.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 68bee4b0-8263-45aa-bd4b-cd44e97fa65b

📥 Commits

Reviewing files that changed from the base of the PR and between 1be7a39 and 9359380.

📒 Files selected for processing (5)
  • internal/controller/postgres/assets_test.go
  • internal/controller/postgres/deployment.go
  • internal/controller/utils/utils.go
  • internal/controller/utils/utils_comparison_test.go
  • test/e2e/all_features_test.go

📝 Walkthrough

Walkthrough

Adds graceful shutdown support to the Postgres deployment by wiring a PreStop exec hook that runs pg_ctl stop and setting TerminationGracePeriodSeconds to 60. Extends DeploymentSpecEqual and ContainerSpecEqual to compare these new fields, and adds corresponding unit and e2e test assertions.

Changes

Postgres Graceful Shutdown

Layer / File(s) Summary
Deployment generation and equality helpers
internal/controller/postgres/deployment.go, internal/controller/utils/utils.go
GeneratePostgresDeployment adds a Lifecycle.PreStop exec hook running pg_ctl stop and sets TerminationGracePeriodSeconds to 60 on the pod spec. DeploymentSpecEqual and ContainerSpecEqual are extended to include TerminationGracePeriodSeconds and Lifecycle in their equality checks.
Unit and e2e test coverage
internal/controller/postgres/assets_test.go, internal/controller/utils/utils_comparison_test.go, test/e2e/all_features_test.go
Unit tests assert the generated Deployment contains the expected PreStop command and TerminationGracePeriodSeconds. Equality comparison tests verify that differing Lifecycle or TerminationGracePeriodSeconds values produce the correct inequality/equality results. The e2e test validates both fields on the live Postgres pod.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a preStop lifecycle hook to prevent postgres pod crash-loops after unclean shutdown, which is directly reflected in all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@openshift-ci

openshift-ci Bot commented Jun 16, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign bparees for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci

openshift-ci Bot commented Jun 16, 2026

Copy link
Copy Markdown

@sriroopar: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/bundle-e2e-4-21 9359380 link true /test bundle-e2e-4-21

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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