Skip to content

Comments

Fix switchover support#20

Merged
eminano merged 5 commits intomainfrom
fix-switchover-support
Sep 4, 2025
Merged

Fix switchover support#20
eminano merged 5 commits intomainfrom
fix-switchover-support

Conversation

@eminano
Copy link
Contributor

@eminano eminano commented Sep 3, 2025

Until now the sidecar was only injected into the primary, which caused issues during switch over due to the pod spec not being aligned between the current primary and the target primary, resulting in a crash loop backoff.

In order to resolve this, the sidecar container will be now injecting into all cluster pods, but only the primary will hibernate/suspend backups. This allows for a more robust logic, where a switchover is supported and the scale to zero behaviour is seamlessly transitioned to the new primary.

For now, only the primary keeps track of activity, so any switchover/restart will reset the inactivity timeout timer.

@eminano eminano requested a review from Copilot September 3, 2025 16:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes switchover support by ensuring the sidecar is injected into all cluster pods, not just the primary. Previously, sidecars were only injected into the primary pod, causing issues during switchovers when pod specs didn't align between current and target primaries.

  • Removes the primary-only sidecar injection restriction in the lifecycle plugin
  • Adds logic to ensure only the primary pod performs hibernation operations while all pods monitor activity
  • Updates tests to include current primary information and adds new test scenarios for primary detection

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/plugin/lifecycle/lifecycle.go Removes the check that restricted sidecar injection to primary pods only
internal/sidecar/scale_to_zero.go Adds isPrimary() method and logic to ensure only primary pods hibernate clusters
internal/sidecar/scale_to_zero_test.go Updates existing tests and adds new test cases for primary detection scenarios
doc/development.md Updates documentation to reflect the new behavior of all pods having sidecars
README.md Updates overview to clarify that sidecars are injected into all pods
.pre-commit-config.yaml Adds a local hook to generate manifests during pre-commit checks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@eminano eminano added the build-images Trigger PR docker images/manifest building for testing (requires approval) label Sep 4, 2025
@github-actions
Copy link

github-actions bot commented Sep 4, 2025

🚀 PR Images Built Successfully!

Image Tags:

  • Plugin: ghcr.io/xataio/cnpg-i-scale-to-zero:pr-20-e8f1d440ebe03a7cba1e561f6f638ae5c69982e6
  • Sidecar: ghcr.io/xataio/cnpg-i-scale-to-zero-sidecar:pr-20-e8f1d440ebe03a7cba1e561f6f638ae5c69982e6

Manifest: Download the kubernetes-manifest-pr-20 artifact from this workflow run.

These images are for testing purposes and will be automatically cleaned up when the PR is closed.

@eminano eminano added build-images Trigger PR docker images/manifest building for testing (requires approval) and removed build-images Trigger PR docker images/manifest building for testing (requires approval) labels Sep 4, 2025
@eminano eminano deployed to pr-image-build September 4, 2025 10:34 — with GitHub Actions Active
@github-actions
Copy link

github-actions bot commented Sep 4, 2025

🚀 PR Images Built Successfully!

Image Tags:

  • Plugin: ghcr.io/xataio/cnpg-i-scale-to-zero:pr-20-20d8ea62418968ea1bcf2b9ae4bc2e85bfed0d17
  • Sidecar: ghcr.io/xataio/cnpg-i-scale-to-zero-sidecar:pr-20-20d8ea62418968ea1bcf2b9ae4bc2e85bfed0d17

Manifest: Download the kubernetes-manifest-pr-20 artifact from this workflow run.

These images are for testing purposes and will be automatically cleaned up when the PR is closed.

@eminano eminano removed the build-images Trigger PR docker images/manifest building for testing (requires approval) label Sep 4, 2025
Comment on lines +100 to +103
if !s.isPrimary(cluster) {
// reset last active time when it's not the primary to make sure
// when there's a switchover, the new primary has a clean state
s.lastActive = time.Time{}
Copy link
Member

Choose a reason for hiding this comment

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

👍

@eminano eminano merged commit 0f081bc into main Sep 4, 2025
8 checks passed
@eminano eminano deleted the fix-switchover-support branch September 4, 2025 10:52
@github-actions
Copy link

github-actions bot commented Sep 4, 2025

🧹 PR Resources Cleaned Up

Since this PR has been merged, the following test resources have been automatically deleted:

  • Container images: pr-20-*
  • Kubernetes manifest artifacts

Thanks for testing! 🎉

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.

3 participants