mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
fix: replica source object store on replica clusters being promoted
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
parent
781a2f7401
commit
9d08ac1a95
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
|
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
|
||||||
"github.com/cloudnative-pg/machinery/pkg/log"
|
"github.com/cloudnative-pg/machinery/pkg/log"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||||
@ -131,30 +132,40 @@ func (w WALServiceImplementation) Restore(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var objectStore barmancloudv1.ObjectStore
|
|
||||||
var serverName string
|
var serverName string
|
||||||
|
var objectStoreKey types.NamespacedName
|
||||||
|
|
||||||
|
var promotionToken string
|
||||||
|
if configuration.Cluster.Spec.ReplicaCluster != nil {
|
||||||
|
promotionToken = configuration.Cluster.Spec.ReplicaCluster.PromotionToken
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case promotionToken != "" && configuration.Cluster.Status.LastPromotionToken != promotionToken:
|
||||||
|
// This is a replica cluster that is being promoted to a primary cluster
|
||||||
|
// Recover from the replica source object store
|
||||||
|
serverName = configuration.ReplicaSourceServerName
|
||||||
|
objectStoreKey = configuration.GetReplicaSourceBarmanObjectKey()
|
||||||
|
|
||||||
case configuration.Cluster.IsReplica() && configuration.Cluster.Status.CurrentPrimary == w.InstanceName:
|
case configuration.Cluster.IsReplica() && configuration.Cluster.Status.CurrentPrimary == w.InstanceName:
|
||||||
// Designated primary on replica cluster, using replica source object store
|
// Designated primary on replica cluster, using replica source object store
|
||||||
serverName = configuration.ReplicaSourceServerName
|
serverName = configuration.ReplicaSourceServerName
|
||||||
if err := w.Client.Get(ctx, configuration.GetReplicaSourceBarmanObjectKey(), &objectStore); err != nil {
|
objectStoreKey = configuration.GetReplicaSourceBarmanObjectKey()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
case configuration.Cluster.Status.CurrentPrimary == "":
|
case configuration.Cluster.Status.CurrentPrimary == "":
|
||||||
// Recovery from object store, using recovery object store
|
// Recovery from object store, using recovery object store
|
||||||
serverName = configuration.RecoveryServerName
|
serverName = configuration.RecoveryServerName
|
||||||
if err := w.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &objectStore); err != nil {
|
objectStoreKey = configuration.GetRecoveryBarmanObjectKey()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Using cluster object store
|
// Using cluster object store
|
||||||
serverName = configuration.ServerName
|
serverName = configuration.ServerName
|
||||||
if err := w.Client.Get(ctx, configuration.GetBarmanObjectKey(), &objectStore); err != nil {
|
objectStoreKey = configuration.GetBarmanObjectKey()
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
|
var objectStore barmancloudv1.ObjectStore
|
||||||
|
if err := w.Client.Get(ctx, objectStoreKey, &objectStore); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
contextLogger.Info(
|
contextLogger.Info(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user