Skip to content

feat(postgres): add serverName parameter for backup recovery#2362

Open
IvanHunters wants to merge 2 commits intomainfrom
feat/postgres-backup-server-name
Open

feat(postgres): add serverName parameter for backup recovery#2362
IvanHunters wants to merge 2 commits intomainfrom
feat/postgres-backup-server-name

Conversation

@IvanHunters
Copy link
Copy Markdown
Collaborator

@IvanHunters IvanHunters commented Apr 8, 2026

Summary

Add serverName field to bootstrap configuration to support backup recovery when the Barman server name in backup.info differs from the Kubernetes cluster name.

This fixes "no target backup found" errors during CloudNativePG recovery operations.

Problem

CloudNativePG forms the backup path as destinationPath + "postgres-" + oldName, but searches for backups using the server_name field from backup.info. When these values don't match (e.g., cluster name is grafana but server_name is cloud), recovery fails with "no target backup found".

Solution

  • Add optional serverName parameter to bootstrap configuration
  • When specified, CloudNativePG uses this value to search for backups in S3
  • Falls back to oldName when serverName is not provided (backwards compatible)

Changes

  • Add ServerName field to PostgreSQL CRD type definition
  • Add conditional serverName to Cluster externalClusters template
  • Update values.yaml and README.md with serverName documentation
  • Regenerate values.schema.json and postgres.yaml CRD

Test plan

  • Deploy postgres cluster with backups enabled
  • Create backup
  • Create new postgres instance with bootstrap.enabled=true, bootstrap.oldName=<original-name>, and bootstrap.serverName=<value-from-backup.info>
  • Verify recovery completes successfully

Summary by CodeRabbit

  • New Features

    • Added an optional bootstrap.serverName setting to specify the Barman server name from the original cluster’s backup.info (used when that server name differs from the Kubernetes cluster name).
  • Documentation

    • Clarified that bootstrap.oldName must match the serverName value recorded in backup.info; updated docs and examples to reflect the new bootstrap.serverName option.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added an optional serverName field to PostgreSQL Bootstrap to carry the Barman server name from the old cluster's backup.info; updated comments, Helm templates, values, and schema/docs to surface and document the new field and clarify that oldName matches backup.info's serverName.

Changes

Cohort / File(s) Summary
Core Type Definition
api/apps/v1alpha1/postgresql/types.go
Added ServerName string (json:"serverName,omitempty") to Bootstrap. Updated OldName comment to state it matches serverName in backup.info.
Documentation & Values Schema
packages/apps/postgres/README.md, packages/apps/postgres/values.schema.json, packages/apps/postgres/values.yaml
Added bootstrap.serverName (string, default "") to docs and schema; clarified bootstrap.oldName descriptions to reference backup.info's serverName; added default bootstrap.serverName: "".
Helm Template
packages/apps/postgres/templates/db.yaml
Conditionally render serverName in spec.bootstrap.externalClusters[].barmanObjectStore when .Values.bootstrap.serverName is set.
CRD / Chart Metadata
packages/system/postgres-rd/cozyrds/postgres.yaml
Updated spec.application.openAPISchema to include spec.bootstrap.serverName and revised spec.bootstrap.oldName description; added ["spec","bootstrap","serverName"] to spec.keysOrder.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I found a name in backup light,

serverName tucked safe and tight,
Old clusters whisper where they've been,
Bootstrap hops them home again. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a serverName parameter to the bootstrap configuration for backup recovery in PostgreSQL.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/postgres-backup-server-name

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a serverName field to the PostgreSQL bootstrap configuration, enabling recovery from backups where the Barman server name does not match the Kubernetes cluster name. The changes encompass Go API types, Helm templates, documentation, and validation schemas. Review feedback highlights a critical issue where the groupName was changed to values.helm.io, which would break API compatibility for existing manifests. Additionally, it was noted that the +kubebuilder:object:root=true marker was moved to an incorrect location, which may interfere with CRD generation tools.

Comment thread api/apps/v1alpha1/postgresql/types.go Outdated
// +kubebuilder:object:generate=true
// +groupName=apps.cozystack.io
// +kubebuilder:object:root=true
// +groupName=values.helm.io
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.

high

The groupName has been changed from apps.cozystack.io to values.helm.io. This appears to be an unintended change, likely caused by a tool update or misconfiguration during code generation. Changing the group name will break API compatibility for the Postgres resource, as existing manifests and tests (e.g., postgres.bats) reference apps.cozystack.io.

Suggested change
// +groupName=values.helm.io
// +groupName=apps.cozystack.io

Comment thread api/apps/v1alpha1/postgresql/types.go Outdated
// Code generated by values-gen. DO NOT EDIT.
// +kubebuilder:object:generate=true
// +groupName=apps.cozystack.io
// +kubebuilder:object:root=true
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.

medium

The +kubebuilder:object:root=true marker has been moved to the package level. In standard Kubebuilder usage, this marker should be placed directly above the struct that represents the root of the CRD (in this case, the Config struct). Moving it to the top of the file may cause issues with CRD generation tools.

kvaps
kvaps previously approved these changes Apr 8, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 8, 2026
@IvanHunters IvanHunters marked this pull request as ready for review April 8, 2026 18:56
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Apr 8, 2026
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 8, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/apps/v1alpha1/postgresql/types.go`:
- Around line 7-8: The generated Postgres artifacts under package postgresql
(types.go and related types/schema/CRD files) are out of sync; rerun the
project's generation flow (the values-gen/tooling used to create these files) to
regenerate the Postgres types/schema/CRD artifacts, verify there are no local
diffs, and commit the updated generated files so the generated code (including
the file that begins with "Code generated by values-gen. DO NOT EDIT." in
package postgresql) is in sync with the repository.

In `@packages/apps/postgres/values.yaml`:
- Around line 156-157: The description for oldName is now misleading: update the
comment for the field oldName to reflect that it represents the previous
Kubernetes cluster name (not the Barman backup.info serverName) and that
serverName should be used when the backup.info serverName differs; specifically,
change the oldName docstring to state it is the previous cluster name used for
recovery lookup and clarify that serverName is an explicit override for the
Barman serverName from backup.info when names differ (referencing the oldName
and serverName fields in the values.yaml).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d7a4a66-7b37-4b2c-a99b-99e8cb878276

📥 Commits

Reviewing files that changed from the base of the PR and between d2361f3 and bd67c6d.

📒 Files selected for processing (6)
  • api/apps/v1alpha1/postgresql/types.go
  • packages/apps/postgres/README.md
  • packages/apps/postgres/templates/db.yaml
  • packages/apps/postgres/values.schema.json
  • packages/apps/postgres/values.yaml
  • packages/system/postgres-rd/cozyrds/postgres.yaml

Comment thread api/apps/v1alpha1/postgresql/types.go Outdated
Comment thread packages/apps/postgres/values.yaml Outdated
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 8, 2026
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from cf948ae to 24439e7 Compare April 8, 2026 19:11
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Apr 8, 2026
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from 24439e7 to 454c956 Compare April 8, 2026 19:17
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Apr 8, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/apps/v1alpha1/postgresql/types.go`:
- Around line 91-93: The comment for the OldName field is misleading; update the
docstring for OldName in types.go (the OldName string `json:"oldName"` field) to
state that it is the previous cluster name before deletion and that it may
differ from the serverName recorded in backup.info (do not claim they "match");
keep it concise and clarify its purpose (e.g., to correlate backups when cluster
names change).

In `@api/apps/v1alpha1/tcpbalancer/types.go`:
- Line 39: The Whitelist field on the TCPBalancer spec is marked with
`omitempty` which can remove the key and cause undefined ACLs in the HAProxy
template; remove `omitempty` from the struct tag on the `Whitelist []string`
field in the TCPBalancer types (the `Whitelist` field in
api/apps/v1alpha1/tcpbalancer/types.go) so the JSON always includes an empty
array when unset, ensuring the templates referencing `whitelist` always receive
a defined value.

In `@packages/apps/vm-disk/values.schema.json`:
- Around line 41-42: The schema lost the object type for the source.upload node
so validation is weakened; update the source generator or source values.yaml to
declare source.upload as an object (matching how source.http and source.image
are defined), then run the cozyvalues-gen regeneration (make generate) to emit
updated values.schema.json artifacts; specifically modify the values.yaml entry
for source.upload to include type: object (and any required properties) or
update the cozyvalues-gen mapping that builds source.upload before regenerating
the schema files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3d7f951-4668-41e3-94fd-f89d0f36a86c

📥 Commits

Reviewing files that changed from the base of the PR and between 24439e7 and cf948ae.

📒 Files selected for processing (58)
  • api/apps/v1alpha1/bucket/types.go
  • api/apps/v1alpha1/clickhouse/types.go
  • api/apps/v1alpha1/foundationdb/types.go
  • api/apps/v1alpha1/harbor/types.go
  • api/apps/v1alpha1/httpcache/types.go
  • api/apps/v1alpha1/kafka/types.go
  • api/apps/v1alpha1/mongodb/types.go
  • api/apps/v1alpha1/nats/types.go
  • api/apps/v1alpha1/openbao/types.go
  • api/apps/v1alpha1/opensearch/types.go
  • api/apps/v1alpha1/postgresql/types.go
  • api/apps/v1alpha1/qdrant/types.go
  • api/apps/v1alpha1/redis/types.go
  • api/apps/v1alpha1/tcpbalancer/types.go
  • api/apps/v1alpha1/tenant/types.go
  • api/apps/v1alpha1/vmdisk/types.go
  • api/apps/v1alpha1/vminstance/types.go
  • api/apps/v1alpha1/vpc/types.go
  • api/apps/v1alpha1/vpn/types.go
  • packages/apps/bucket/values.schema.json
  • packages/apps/clickhouse/values.schema.json
  • packages/apps/foundationdb/values.schema.json
  • packages/apps/harbor/values.schema.json
  • packages/apps/http-cache/values.schema.json
  • packages/apps/kafka/values.schema.json
  • packages/apps/mongodb/values.schema.json
  • packages/apps/nats/values.schema.json
  • packages/apps/openbao/values.schema.json
  • packages/apps/opensearch/values.schema.json
  • packages/apps/qdrant/values.schema.json
  • packages/apps/redis/values.schema.json
  • packages/apps/tcp-balancer/values.schema.json
  • packages/apps/tenant/values.schema.json
  • packages/apps/vm-disk/values.schema.json
  • packages/apps/vm-instance/values.schema.json
  • packages/apps/vpc/values.schema.json
  • packages/apps/vpn/values.schema.json
  • packages/system/clickhouse-rd/cozyrds/clickhouse.yaml
  • packages/system/harbor-rd/cozyrds/harbor.yaml
  • packages/system/harbor/templates/database.yaml
  • packages/system/http-cache-rd/cozyrds/http-cache.yaml
  • packages/system/kafka-rd/cozyrds/kafka.yaml
  • packages/system/keycloak/templates/db.yaml
  • packages/system/mongodb-rd/cozyrds/mongodb.yaml
  • packages/system/monitoring/templates/alerta/alerta-db.yaml
  • packages/system/monitoring/templates/grafana/db.yaml
  • packages/system/nats-rd/cozyrds/nats.yaml
  • packages/system/openbao-rd/cozyrds/openbao.yaml
  • packages/system/opensearch-rd/cozyrds/opensearch.yaml
  • packages/system/qdrant-rd/cozyrds/qdrant.yaml
  • packages/system/redis-rd/cozyrds/redis.yaml
  • packages/system/seaweedfs/templates/database.yaml
  • packages/system/tcp-balancer-rd/cozyrds/tcp-balancer.yaml
  • packages/system/tenant-rd/cozyrds/tenant.yaml
  • packages/system/virtualprivatecloud-rd/cozyrds/virtualprivatecloud.yaml
  • packages/system/vm-disk-rd/cozyrds/vm-disk.yaml
  • packages/system/vm-instance-rd/cozyrds/vm-instance.yaml
  • packages/system/vpn-rd/cozyrds/vpn.yaml
✅ Files skipped from review due to trivial changes (38)
  • packages/apps/bucket/values.schema.json
  • packages/system/harbor/templates/database.yaml
  • packages/apps/nats/values.schema.json
  • packages/system/monitoring/templates/alerta/alerta-db.yaml
  • packages/apps/foundationdb/values.schema.json
  • api/apps/v1alpha1/bucket/types.go
  • packages/apps/tcp-balancer/values.schema.json
  • packages/apps/openbao/values.schema.json
  • packages/apps/vpc/values.schema.json
  • packages/system/tenant-rd/cozyrds/tenant.yaml
  • packages/apps/http-cache/values.schema.json
  • packages/apps/vpn/values.schema.json
  • packages/apps/qdrant/values.schema.json
  • packages/system/vpn-rd/cozyrds/vpn.yaml
  • packages/system/mongodb-rd/cozyrds/mongodb.yaml
  • packages/system/redis-rd/cozyrds/redis.yaml
  • packages/system/openbao-rd/cozyrds/openbao.yaml
  • packages/system/seaweedfs/templates/database.yaml
  • packages/system/opensearch-rd/cozyrds/opensearch.yaml
  • packages/apps/tenant/values.schema.json
  • packages/system/http-cache-rd/cozyrds/http-cache.yaml
  • packages/apps/clickhouse/values.schema.json
  • packages/system/qdrant-rd/cozyrds/qdrant.yaml
  • packages/system/monitoring/templates/grafana/db.yaml
  • packages/system/kafka-rd/cozyrds/kafka.yaml
  • packages/apps/redis/values.schema.json
  • packages/system/nats-rd/cozyrds/nats.yaml
  • packages/system/vm-instance-rd/cozyrds/vm-instance.yaml
  • packages/apps/opensearch/values.schema.json
  • packages/apps/vm-instance/values.schema.json
  • api/apps/v1alpha1/vpc/types.go
  • packages/system/tcp-balancer-rd/cozyrds/tcp-balancer.yaml
  • api/apps/v1alpha1/kafka/types.go
  • api/apps/v1alpha1/opensearch/types.go
  • packages/system/clickhouse-rd/cozyrds/clickhouse.yaml
  • packages/system/virtualprivatecloud-rd/cozyrds/virtualprivatecloud.yaml
  • api/apps/v1alpha1/harbor/types.go
  • packages/system/keycloak/templates/db.yaml

Comment thread api/apps/v1alpha1/postgresql/types.go Outdated
Comment on lines 91 to 93
// Previous cluster name before deletion (matches serverName in backup.info).
// +kubebuilder:default:=""
OldName string `json:"oldName"`
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.

⚠️ Potential issue | 🟡 Minor

Fix misleading OldName docstring.

At Line 91, the comment says old cluster name “matches serverName in backup.info”, but the whole feature exists because these can differ. Please reword to avoid operator confusion.

✏️ Suggested wording
-	// Previous cluster name before deletion (matches serverName in backup.info).
+	// Previous Kubernetes cluster name used in backup path naming.
+	// This may differ from backup.info serverName.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Previous cluster name before deletion (matches serverName in backup.info).
// +kubebuilder:default:=""
OldName string `json:"oldName"`
// Previous Kubernetes cluster name used in backup path naming.
// This may differ from backup.info serverName.
// +kubebuilder:default:=""
OldName string `json:"oldName"`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/apps/v1alpha1/postgresql/types.go` around lines 91 - 93, The comment for
the OldName field is misleading; update the docstring for OldName in types.go
(the OldName string `json:"oldName"` field) to state that it is the previous
cluster name before deletion and that it may differ from the serverName recorded
in backup.info (do not claim they "match"); keep it concise and clarify its
purpose (e.g., to correlate backups when cluster names change).

Comment thread api/apps/v1alpha1/tcpbalancer/types.go Outdated
// List of allowed client networks.
// +kubebuilder:default:={}
HttpAndHttps HttpAndHttps `json:"httpAndHttps"`
Whitelist []string `json:"whitelist,omitempty"`
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.

⚠️ Potential issue | 🟠 Major

Revert omitempty on whitelist to avoid undefined ACL generation.

At Line 39, making whitelist optional can omit the key entirely. In packages/apps/tcp-balancer/templates/configmap.yaml (Lines 42-49), ACL whitelist is defined conditionally but referenced unconditionally, which can break rendered HAProxy config when whitelistHTTP=true and list is absent.

💡 Proposed fix
-	Whitelist []string `json:"whitelist,omitempty"`
+	Whitelist []string `json:"whitelist"`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Whitelist []string `json:"whitelist,omitempty"`
Whitelist []string `json:"whitelist"`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/apps/v1alpha1/tcpbalancer/types.go` at line 39, The Whitelist field on
the TCPBalancer spec is marked with `omitempty` which can remove the key and
cause undefined ACLs in the HAProxy template; remove `omitempty` from the struct
tag on the `Whitelist []string` field in the TCPBalancer types (the `Whitelist`
field in api/apps/v1alpha1/tcpbalancer/types.go) so the JSON always includes an
empty array when unset, ensuring the templates referencing `whitelist` always
receive a defined value.

Comment on lines +41 to +42
"upload": {
"description": "Upload local image.",
"type": "object"
"description": "Upload local image."
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.

⚠️ Potential issue | 🟠 Major

Restore the source.upload object type.

Unlike http and image, upload is now just a description node with no declared object type. That makes this branch effectively untyped in the generated schema and weakens validation for a user-facing input path. Please fix this in the source/generator and regenerate both schema artifacts.

Based on learnings: values.schema.json files in package directories are auto-generated from values.yaml by the cozyvalues-gen tool and regenerated on make generate, so manual edits here will be overwritten.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/apps/vm-disk/values.schema.json` around lines 41 - 42, The schema
lost the object type for the source.upload node so validation is weakened;
update the source generator or source values.yaml to declare source.upload as an
object (matching how source.http and source.image are defined), then run the
cozyvalues-gen regeneration (make generate) to emit updated values.schema.json
artifacts; specifically modify the values.yaml entry for source.upload to
include type: object (and any required properties) or update the cozyvalues-gen
mapping that builds source.upload before regenerating the schema files.

@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch 2 times, most recently from 721ada5 to 0fcaef5 Compare April 8, 2026 19:24
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (3)
packages/system/postgres-rd/cozyrds/postgres.yaml (1)

11-11: ⚠️ Potential issue | 🟡 Minor

Same misleading oldName description in OpenAPI schema.

The embedded JSON schema contains "oldName":{"description":"Previous cluster name before deletion (matches serverName in backup.info)."...} which perpetuates the same misleading text. This should be updated to clarify that oldName is the K8s cluster name and may differ from serverName in backup.info.

The serverName field definition and its description are correct.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/system/postgres-rd/cozyrds/postgres.yaml` at line 11, Update the
OpenAPI description for the bootstrap.oldName property: change the misleading
text that says it "matches serverName in backup.info" to clearly state that
oldName is the Kubernetes cluster name from the previous cluster and may differ
from bootstrap.serverName (which is the Barman/server name stored in
backup.info); edit the "oldName" description in the bootstrap properties to
reflect this distinction.
api/apps/v1alpha1/postgresql/types.go (1)

89-91: ⚠️ Potential issue | 🟡 Minor

OldName docstring is still misleading.

The comment on line 89 states (matches serverName in backup.info), but the entire purpose of this PR is to handle cases where they differ. This contradicts the PR's intent and will confuse operators. The past review flagged this exact issue but it remains unaddressed.

Since this is an auto-generated file, please update the source (likely in values.yaml or schema definition) and regenerate.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/apps/v1alpha1/postgresql/types.go` around lines 89 - 91, Update the
misleading docstring for the OldName field: change the comment to state that
OldName is the previous cluster name before deletion and may differ from
serverName in backup.info (i.e., it records the original name used prior to
deletion/restore). Make this change in the source schema (e.g., the values.yaml
or the CRD/schema definition that generates
api/apps/v1alpha1/postgresql/types.go) rather than editing the generated file
directly, then regenerate the API/types.go to apply the corrected comment for
the OldName field.
packages/apps/postgres/values.yaml (1)

156-157: ⚠️ Potential issue | 🟡 Minor

oldName description remains misleading despite being marked as addressed.

Line 156 still contains (matches serverName in backup.info) which contradicts the purpose of the new serverName field. The past review flagged this and it was marked as addressed in commit 0fcaef5, but the text is unchanged.

Suggested fix
-## `@field` {string} oldName - Previous cluster name before deletion (matches serverName in backup.info).
+## `@field` {string} oldName - Previous Kubernetes cluster name before deletion. May differ from serverName in backup.info.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/apps/postgres/values.yaml` around lines 156 - 157, The current
description for the values.yaml field oldName is still incorrect — it claims
"(matches serverName in backup.info)" which conflicts with the new serverName
field; update the oldName description to reflect that it is the previous
Kubernetes cluster/cluster resource name (e.g., "Previous Kubernetes cluster
name before deletion") and remove the parenthetical about backup.info, and
ensure the serverName field description remains the place to document the Barman
server name from backup.info; change only the text for oldName in values.yaml
(referencing the oldName and serverName fields).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@api/apps/v1alpha1/postgresql/types.go`:
- Around line 89-91: Update the misleading docstring for the OldName field:
change the comment to state that OldName is the previous cluster name before
deletion and may differ from serverName in backup.info (i.e., it records the
original name used prior to deletion/restore). Make this change in the source
schema (e.g., the values.yaml or the CRD/schema definition that generates
api/apps/v1alpha1/postgresql/types.go) rather than editing the generated file
directly, then regenerate the API/types.go to apply the corrected comment for
the OldName field.

In `@packages/apps/postgres/values.yaml`:
- Around line 156-157: The current description for the values.yaml field oldName
is still incorrect — it claims "(matches serverName in backup.info)" which
conflicts with the new serverName field; update the oldName description to
reflect that it is the previous Kubernetes cluster/cluster resource name (e.g.,
"Previous Kubernetes cluster name before deletion") and remove the parenthetical
about backup.info, and ensure the serverName field description remains the place
to document the Barman server name from backup.info; change only the text for
oldName in values.yaml (referencing the oldName and serverName fields).

In `@packages/system/postgres-rd/cozyrds/postgres.yaml`:
- Line 11: Update the OpenAPI description for the bootstrap.oldName property:
change the misleading text that says it "matches serverName in backup.info" to
clearly state that oldName is the Kubernetes cluster name from the previous
cluster and may differ from bootstrap.serverName (which is the Barman/server
name stored in backup.info); edit the "oldName" description in the bootstrap
properties to reflect this distinction.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: da8ec22b-aed1-4db8-915b-92a7bcde7693

📥 Commits

Reviewing files that changed from the base of the PR and between cf948ae and 0fcaef5.

📒 Files selected for processing (6)
  • api/apps/v1alpha1/postgresql/types.go
  • packages/apps/postgres/README.md
  • packages/apps/postgres/templates/db.yaml
  • packages/apps/postgres/values.schema.json
  • packages/apps/postgres/values.yaml
  • packages/system/postgres-rd/cozyrds/postgres.yaml
✅ Files skipped from review due to trivial changes (1)
  • packages/apps/postgres/templates/db.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/apps/postgres/README.md
  • packages/apps/postgres/values.schema.json

@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from 0fcaef5 to 8b3e346 Compare April 8, 2026 20:02
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
api/apps/v1alpha1/postgresql/types.go (1)

89-97: ⚠️ Potential issue | 🟡 Minor

Correct OldName semantics to avoid misconfiguration.

At Line 89, describing oldName as matching backup.info.serverName conflicts with the newly added serverName field. oldName should represent the previous Kubernetes cluster name/path identifier, while serverName is the Barman value from backup.info.

✏️ Proposed wording fix
-	// Previous cluster name before deletion (matches serverName in backup.info).
+	// Previous Kubernetes cluster name used for backup path naming.
+	// This may differ from backup.info serverName.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/apps/v1alpha1/postgresql/types.go` around lines 89 - 97, The comment for
OldName is incorrect and must be rewritten to state that OldName is the previous
Kubernetes cluster name/path identifier (the cluster's prior k8s resource name),
not the Barman backup.info.serverName; update the OldName field comment on the
Postgresql spec to reflect that semantic, and ensure the ServerName field
comment (ServerName) clearly states it is the Barman server name taken from
backup.info for use when the original cluster used a different serverName than
its Kubernetes cluster name.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@api/apps/v1alpha1/postgresql/types.go`:
- Around line 89-97: The comment for OldName is incorrect and must be rewritten
to state that OldName is the previous Kubernetes cluster name/path identifier
(the cluster's prior k8s resource name), not the Barman backup.info.serverName;
update the OldName field comment on the Postgresql spec to reflect that
semantic, and ensure the ServerName field comment (ServerName) clearly states it
is the Barman server name taken from backup.info for use when the original
cluster used a different serverName than its Kubernetes cluster name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3564c423-b0ce-4f58-8a8a-a2285dfd020e

📥 Commits

Reviewing files that changed from the base of the PR and between 0fcaef5 and 8b3e346.

📒 Files selected for processing (6)
  • api/apps/v1alpha1/postgresql/types.go
  • packages/apps/postgres/README.md
  • packages/apps/postgres/templates/db.yaml
  • packages/apps/postgres/values.schema.json
  • packages/apps/postgres/values.yaml
  • packages/system/postgres-rd/cozyrds/postgres.yaml
✅ Files skipped from review due to trivial changes (1)
  • packages/apps/postgres/templates/db.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/apps/postgres/values.yaml
  • packages/apps/postgres/README.md

Copy link
Copy Markdown
Contributor

@myasnikovdaniil myasnikovdaniil left a comment

Choose a reason for hiding this comment

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

Review + E2E Test Results

E2E Testing

Tested on a dev cluster:

Positive test (PASS): Deployed a postgres cluster with backups, inserted test data (3 rows), triggered backup. Then deployed a new cluster with oldName=pg-source (intentionally mismatched) and serverName=pg-test-restore (the actual S3 path). Recovery completed successfully — all 3 rows present. The serverName parameter correctly directs CNPG to the right S3 path.

Negative test (PASS): Same setup but without serverName. Recovery pods crash-loop with "no target backup found" — confirming this PR fixes a real issue.

Code Review

Template, schema, CRD — all correct. The conditional in db.yaml works as expected, serverName is correctly not in the required array, keysOrder is updated, all 6 files are consistent. See inline comments for the one description issue found.

Comment thread packages/apps/postgres/values.yaml Outdated
## @field {bool} enabled - Whether to restore from a backup.
## @field {string} [recoveryTime] - Timestamp (RFC3339) for point-in-time recovery; empty means latest.
## @field {string} oldName - Previous cluster name before deletion.
## @field {string} oldName - Previous cluster name before deletion (matches serverName in backup.info).
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.

This parenthetical is misleading. oldName maps to externalClusters[].name — a local reference label that wires bootstrap.recovery.source to the external cluster entry. It does not necessarily match backup.info's server_name.

The whole point of this PR is to handle the case where they don't match, so stating they match here contradicts the PR's own purpose.

Suggestion: revert to the original description:

## @field {string} oldName - Previous cluster name before deletion.

Then re-run make generate to propagate.

Comment thread packages/apps/postgres/values.yaml Outdated
## @field {string} [recoveryTime] - Timestamp (RFC3339) for point-in-time recovery; empty means latest.
## @field {string} oldName - Previous cluster name before deletion.
## @field {string} oldName - Previous cluster name before deletion (matches serverName in backup.info).
## @field {string} [serverName] - Barman server name from the old cluster's backup.info. Use when the original cluster used a different serverName than its Kubernetes cluster name.
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.

The description references backup.info which implies users should open that file and copy a value. Per CNPG docs, barmanObjectStore.serverName is the S3 path prefix barman uses — it defaults to the cluster's metadata.name.

Also "Kubernetes cluster name" is ambiguous (K8s resource name vs. the K8s cluster itself).

Suggested rewording:

## @field {string} [serverName] - Barman server name (S3 path prefix) used by the original cluster when writing backups. Set this only when the original cluster had an explicit barmanObjectStore.serverName that differed from its Kubernetes resource name.

barmanObjectStore:
destinationPath: {{ .Values.backup.destinationPath }}
{{- if .Values.bootstrap.serverName }}
serverName: {{ .Values.bootstrap.serverName }}
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.

Looks good — the {{- if }} guard correctly omits the field when empty, and the indentation is correct within barmanObjectStore. Verified with helm template rendering and E2E test.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 21, 2026
Add serverName field to bootstrap configuration to explicitly specify
Barman server name from backup.info. This fixes "no target backup found"
errors when server_name in backup.info differs from Kubernetes cluster name.

Signed-off-by: IvanHunters <[email protected]>
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from 2de16de to 82afa31 Compare April 21, 2026 10:31
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 21, 2026
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from 82afa31 to 91358c2 Compare April 21, 2026 10:38
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 21, 2026
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch 2 times, most recently from 8ec5c4b to af988b5 Compare April 21, 2026 10:49
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 21, 2026
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from af988b5 to be0e328 Compare April 21, 2026 10:51
Update oldName and serverName field descriptions based on code review
feedback to avoid confusion about their actual roles:

- oldName: Remove misleading "(matches serverName in backup.info)"
  text. This field represents the Kubernetes cluster resource name,
  not the Barman server name.

- serverName: Provide clearer explanation that it's the S3 path prefix
  (barmanObjectStore.serverName) used by the original cluster, and should
  only be set when it differs from the Kubernetes resource name.

Updated in:
- values.yaml (source of truth for field documentation)
- types.go (Go API type comments)
- values.schema.json (JSON schema for validation)
- postgres.yaml (CRD with embedded OpenAPI schema)

Signed-off-by: IvanHunters <[email protected]>
@IvanHunters IvanHunters force-pushed the feat/postgres-backup-server-name branch from be0e328 to 9f41dc3 Compare April 21, 2026 11:35
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Apr 21, 2026
*out = new(v1.TypedLocalObjectReference)
(*in).DeepCopyInto(*out)
}
if in.Options != nil {
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.

Lets remove this change for clear git history, I will bring it back with new PR and fixed precommit checks to always run make generate.

@dosubot dosubot Bot removed the lgtm This PR has been approved by a maintainer label Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants