@@ -20,23 +20,17 @@ import (
2020
2121 barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
2222 "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
23+ "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/operator/config"
2324)
2425
2526// WALServiceImplementation is the implementation of the WAL Service
2627type WALServiceImplementation struct {
2728 wal.UnimplementedWALServer
28- ClusterObjectKey client.ObjectKey
29- Client client.Client
30- InstanceName string
31- SpoolDirectory string
32- PGDataPath string
33- PGWALPath string
34-
35- BarmanObjectKey client.ObjectKey
36- ServerName string
37-
38- RecoveryBarmanObjectKey client.ObjectKey
39- RecoveryServerName string
29+ Client client.Client
30+ InstanceName string
31+ SpoolDirectory string
32+ PGDataPath string
33+ PGWALPath string
4034}
4135
4236// GetCapabilities implements the WALService interface
@@ -72,13 +66,13 @@ func (w WALServiceImplementation) Archive(
7266 contextLogger := log .FromContext (ctx )
7367 contextLogger .Debug ("starting wal archive" )
7468
75- var cluster cnpgv1. Cluster
76- if err := w . Client . Get ( ctx , w . ClusterObjectKey , & cluster ); err != nil {
69+ configuration , err := config . NewFromClusterJSON ( request . ClusterDefinition )
70+ if err != nil {
7771 return nil , err
7872 }
7973
8074 var objectStore barmancloudv1.ObjectStore
81- if err := w .Client .Get (ctx , w . BarmanObjectKey , & objectStore ); err != nil {
75+ if err := w .Client .Get (ctx , configuration . GetBarmanObjectKey () , & objectStore ); err != nil {
8276 return nil , err
8377 }
8478
@@ -106,7 +100,7 @@ func (w WALServiceImplementation) Archive(
106100 return nil , err
107101 }
108102
109- options , err := arch .BarmanCloudWalArchiveOptions (ctx , & objectStore .Spec .Configuration , w .ServerName )
103+ options , err := arch .BarmanCloudWalArchiveOptions (ctx , & objectStore .Spec .Configuration , configuration .ServerName )
110104 if err != nil {
111105 return nil , err
112106 }
@@ -131,39 +125,39 @@ func (w WALServiceImplementation) Restore(
131125 walName := request .GetSourceWalName ()
132126 destinationPath := request .GetDestinationFileName ()
133127
134- var cluster cnpgv1. Cluster
135- if err := w . Client . Get ( ctx , w . ClusterObjectKey , & cluster ); err != nil {
128+ configuration , err := config . NewFromClusterJSON ( request . ClusterDefinition )
129+ if err != nil {
136130 return nil , err
137131 }
138132
139133 var objectStore barmancloudv1.ObjectStore
140134 var serverName string
141135
142136 switch {
143- case cluster . IsReplica () && cluster .Status .CurrentPrimary == w .InstanceName :
144- // Designated primary on replica cluster, using recovery object store
145- serverName = w . RecoveryServerName
146- if err := w .Client .Get (ctx , w . RecoveryBarmanObjectKey , & objectStore ); err != nil {
137+ case configuration . Cluster . IsReplica () && configuration . Cluster .Status .CurrentPrimary == w .InstanceName :
138+ // Designated primary on replica cluster, using replica source object store
139+ serverName = configuration . ReplicaSourceServerName
140+ if err := w .Client .Get (ctx , configuration . GetReplicaSourceBarmanObjectKey () , & objectStore ); err != nil {
147141 return nil , err
148142 }
149143
150- case cluster .Status .CurrentPrimary == "" :
144+ case configuration . Cluster .Status .CurrentPrimary == "" :
151145 // Recovery from object store, using recovery object store
152- serverName = w .RecoveryServerName
153- if err := w .Client .Get (ctx , w . RecoveryBarmanObjectKey , & objectStore ); err != nil {
146+ serverName = configuration .RecoveryServerName
147+ if err := w .Client .Get (ctx , configuration . GetRecoveryBarmanObjectKey () , & objectStore ); err != nil {
154148 return nil , err
155149 }
156150
157151 default :
158152 // Using cluster object store
159- serverName = w .ServerName
160- if err := w .Client .Get (ctx , w . BarmanObjectKey , & objectStore ); err != nil {
153+ serverName = configuration .ServerName
154+ if err := w .Client .Get (ctx , configuration . GetBarmanObjectKey () , & objectStore ); err != nil {
161155 return nil , err
162156 }
163157 }
164158
165159 return & wal.WALRestoreResult {}, w .restoreFromBarmanObjectStore (
166- ctx , & cluster , & objectStore , serverName , walName , destinationPath )
160+ ctx , configuration . Cluster , & objectStore , serverName , walName , destinationPath )
167161}
168162
169163func (w WALServiceImplementation ) restoreFromBarmanObjectStore (
@@ -246,7 +240,11 @@ func (w WALServiceImplementation) restoreFromBarmanObjectStore(
246240 // is the one that PostgreSQL has requested to restore.
247241 // The failure has already been logged in walRestorer.RestoreList method
248242 if walStatus [0 ].Err != nil {
249- return walStatus [0 ].Err
243+ if errors .Is (walStatus [0 ].Err , barmanRestorer .ErrWALNotFound ) {
244+ return WALNotFoundError {}
245+ } else {
246+ return walStatus [0 ].Err
247+ }
250248 }
251249
252250 // We skip this step if streaming connection is not available
0 commit comments