Skip to content

Commit 4656d44

Browse files
authored
fix: replica source object store on replica clusters being promoted (#96)
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent 781a2f7 commit 4656d44

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

internal/cnpgi/common/wal.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
1717
"github.com/cloudnative-pg/machinery/pkg/log"
1818
apierrors "k8s.io/apimachinery/pkg/api/errors"
19+
"k8s.io/apimachinery/pkg/types"
1920
"sigs.k8s.io/controller-runtime/pkg/client"
2021

2122
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
@@ -131,30 +132,40 @@ func (w WALServiceImplementation) Restore(
131132
return nil, err
132133
}
133134

134-
var objectStore barmancloudv1.ObjectStore
135135
var serverName string
136+
var objectStoreKey types.NamespacedName
137+
138+
var promotionToken string
139+
if configuration.Cluster.Spec.ReplicaCluster != nil {
140+
promotionToken = configuration.Cluster.Spec.ReplicaCluster.PromotionToken
141+
}
136142

137143
switch {
144+
case promotionToken != "" && configuration.Cluster.Status.LastPromotionToken != promotionToken:
145+
// This is a replica cluster that is being promoted to a primary cluster
146+
// Recover from the replica source object store
147+
serverName = configuration.ReplicaSourceServerName
148+
objectStoreKey = configuration.GetReplicaSourceBarmanObjectKey()
149+
138150
case configuration.Cluster.IsReplica() && configuration.Cluster.Status.CurrentPrimary == w.InstanceName:
139151
// Designated primary on replica cluster, using replica source object store
140152
serverName = configuration.ReplicaSourceServerName
141-
if err := w.Client.Get(ctx, configuration.GetReplicaSourceBarmanObjectKey(), &objectStore); err != nil {
142-
return nil, err
143-
}
153+
objectStoreKey = configuration.GetReplicaSourceBarmanObjectKey()
144154

145155
case configuration.Cluster.Status.CurrentPrimary == "":
146156
// Recovery from object store, using recovery object store
147157
serverName = configuration.RecoveryServerName
148-
if err := w.Client.Get(ctx, configuration.GetRecoveryBarmanObjectKey(), &objectStore); err != nil {
149-
return nil, err
150-
}
158+
objectStoreKey = configuration.GetRecoveryBarmanObjectKey()
151159

152160
default:
153161
// Using cluster object store
154162
serverName = configuration.ServerName
155-
if err := w.Client.Get(ctx, configuration.GetBarmanObjectKey(), &objectStore); err != nil {
156-
return nil, err
157-
}
163+
objectStoreKey = configuration.GetBarmanObjectKey()
164+
}
165+
166+
var objectStore barmancloudv1.ObjectStore
167+
if err := w.Client.Get(ctx, objectStoreKey, &objectStore); err != nil {
168+
return nil, err
158169
}
159170

160171
contextLogger.Info(

0 commit comments

Comments
 (0)