Add standby_primary_slot and extend tests

This commit is contained in:
Polina Bungina 2026-01-15 15:10:01 +01:00
parent ce59afee90
commit 0f45521c0b
6 changed files with 45 additions and 8 deletions

View File

@ -493,6 +493,8 @@ spec:
type: string
standby_port:
type: string
standby_primary_slot_name:
type: string
oneOf:
- required:
- s3_wal_path

View File

@ -477,6 +477,10 @@ Note that `s3_wal_path` and `gs_wal_path` are mutually exclusive.
TCP port on which the primary is listening for connections. Patroni will
use `"5432"` if not set.
* **standby_primary_slot_name**
name of the replication slot to use on the primary server when streaming
from a remote primary. Optional.
## Volume properties
Those parameters are grouped under the `volume` top-level key and define the

View File

@ -3949,6 +3949,8 @@ spec:
type: string
standby_port:
type: string
standby_primary_slot_name:
type: string
type: object
streams:
items:

View File

@ -250,10 +250,11 @@ type Patroni struct {
// standby_host can be specified alone or together with either s3_wal_path OR gs_wal_path (mutually exclusive).
// At least one field must be specified. s3_wal_path and gs_wal_path are mutually exclusive.
type StandbyDescription struct {
S3WalPath string `json:"s3_wal_path,omitempty"`
GSWalPath string `json:"gs_wal_path,omitempty"`
StandbyHost string `json:"standby_host,omitempty"`
StandbyPort string `json:"standby_port,omitempty"`
S3WalPath string `json:"s3_wal_path,omitempty"`
GSWalPath string `json:"gs_wal_path,omitempty"`
StandbyHost string `json:"standby_host,omitempty"`
StandbyPort string `json:"standby_port,omitempty"`
StandbyPrimarySlotName string `json:"standby_primary_slot_name,omitempty"`
}
// TLSDescription specs TLS properties

View File

@ -2207,6 +2207,12 @@ func (c *Cluster) generateStandbyEnvironment(description *acidv1.StandbyDescript
Value: description.StandbyPort,
})
}
if description.StandbyPrimarySlotName != "" {
result = append(result, v1.EnvVar{
Name: "STANDBY_PRIMARY_SLOT_NAME",
Value: description.StandbyPrimarySlotName,
})
}
}
// WAL archive can be specified with or without standby_host
@ -2226,10 +2232,6 @@ func (c *Cluster) generateStandbyEnvironment(description *acidv1.StandbyDescript
})
result = append(result, v1.EnvVar{Name: "STANDBY_METHOD", Value: "STANDBY_WITH_WALE"})
result = append(result, v1.EnvVar{Name: "STANDBY_WAL_BUCKET_SCOPE_PREFIX", Value: ""})
} else if description.StandbyHost == "" {
// Neither WAL path nor standby_host specified
c.logger.Error("no WAL path or standby_host specified in standby section")
return result
}
return result

View File

@ -1382,6 +1382,19 @@ func TestStandbyEnv(t *testing.T) {
envPos: 0,
envLen: 4,
},
{
subTest: "verify S3 WAL env with standby host",
standbyOpts: &acidv1.StandbyDescription{
S3WalPath: "s3://some/path/",
StandbyHost: "remote-primary",
},
env: v1.EnvVar{
Name: "STANDBY_WALE_S3_PREFIX",
Value: "s3://some/path/",
},
envPos: 1,
envLen: 4,
},
{
subTest: "from remote primary with GCS WAL path",
standbyOpts: &acidv1.StandbyDescription{
@ -1395,6 +1408,19 @@ func TestStandbyEnv(t *testing.T) {
envPos: 0,
envLen: 4,
},
{
subTest: "from remote primary with slot name",
standbyOpts: &acidv1.StandbyDescription{
StandbyHost: "remote-primary",
StandbyPrimarySlotName: "my_slot",
},
env: v1.EnvVar{
Name: "STANDBY_PRIMARY_SLOT_NAME",
Value: "my_slot",
},
envPos: 1,
envLen: 2,
},
}
var cluster = New(