1- package instance
1+ package common
22
33import (
44 "context"
@@ -19,12 +19,12 @@ import (
1919 "sigs.k8s.io/controller-runtime/pkg/client"
2020
2121 barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
22- "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
2322 "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
2423)
2524
2625// WALServiceImplementation is the implementation of the WAL Service
2726type WALServiceImplementation struct {
27+ ServerName string
2828 BarmanObjectKey client.ObjectKey
2929 ClusterObjectKey client.ObjectKey
3030 Client client.Client
@@ -73,16 +73,6 @@ func (w WALServiceImplementation) Archive(
7373 return nil , err
7474 }
7575
76- // TODO: refactor this code elsewhere
77- serverName := cluster .Name
78- for _ , plugin := range cluster .Spec .Plugins {
79- if plugin .IsEnabled () && plugin .Name == metadata .PluginName {
80- if pluginServerName , ok := plugin .Parameters ["serverName" ]; ok {
81- serverName = pluginServerName
82- }
83- }
84- }
85-
8676 var objectStore barmancloudv1.ObjectStore
8777 if err := w .Client .Get (ctx , w .BarmanObjectKey , & objectStore ); err != nil {
8878 return nil , err
@@ -112,7 +102,7 @@ func (w WALServiceImplementation) Archive(
112102 return nil , err
113103 }
114104
115- options , err := arch .BarmanCloudWalArchiveOptions (ctx , & objectStore .Spec .Configuration , serverName )
105+ options , err := arch .BarmanCloudWalArchiveOptions (ctx , & objectStore .Spec .Configuration , w . ServerName )
116106 if err != nil {
117107 return nil , err
118108 }
@@ -152,7 +142,7 @@ func (w WALServiceImplementation) Restore(
152142
153143 barmanConfiguration := & objectStore .Spec .Configuration
154144
155- env := common . GetRestoreCABundleEnv (barmanConfiguration )
145+ env := GetRestoreCABundleEnv (barmanConfiguration )
156146 credentialsEnv , err := barmanCredentials .EnvSetBackupCloudCredentials (
157147 ctx ,
158148 w .Client ,
@@ -163,19 +153,9 @@ func (w WALServiceImplementation) Restore(
163153 if err != nil {
164154 return nil , fmt .Errorf ("while getting recover credentials: %w" , err )
165155 }
166- env = common .MergeEnv (env , credentialsEnv )
167-
168- // TODO: refactor this code elsewhere
169- serverName := cluster .Name
170- for _ , plugin := range cluster .Spec .Plugins {
171- if plugin .IsEnabled () && plugin .Name == metadata .PluginName {
172- if pluginServerName , ok := plugin .Parameters ["serverName" ]; ok {
173- serverName = pluginServerName
174- }
175- }
176- }
156+ env = MergeEnv (env , credentialsEnv )
177157
178- options , err := barmanCommand .CloudWalRestoreOptions (ctx , barmanConfiguration , serverName )
158+ options , err := barmanCommand .CloudWalRestoreOptions (ctx , barmanConfiguration , w . ServerName )
179159 if err != nil {
180160 return nil , fmt .Errorf ("while getting barman-cloud-wal-restore options: %w" , err )
181161 }
0 commit comments