Skip to content

Commit 4357897

Browse files
committed
feat: add wal-restore capabilities during restore
Signed-off-by: Armando Ruocco <[email protected]>
1 parent b00706b commit 4357897

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package instance
1+
package common
22

33
import (
44
"context"
@@ -19,7 +19,6 @@ 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

@@ -152,7 +151,7 @@ func (w WALServiceImplementation) Restore(
152151

153152
barmanConfiguration := &objectStore.Spec.Configuration
154153

155-
env := common.GetRestoreCABundleEnv(barmanConfiguration)
154+
env := GetRestoreCABundleEnv(barmanConfiguration)
156155
credentialsEnv, err := barmanCredentials.EnvSetBackupCloudCredentials(
157156
ctx,
158157
w.Client,
@@ -163,7 +162,7 @@ func (w WALServiceImplementation) Restore(
163162
if err != nil {
164163
return nil, fmt.Errorf("while getting recover credentials: %w", err)
165164
}
166-
env = common.MergeEnv(env, credentialsEnv)
165+
env = MergeEnv(env, credentialsEnv)
167166

168167
// TODO: refactor this code elsewhere
169168
serverName := cluster.Name
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package instance
17+
package common
1818

1919
import (
2020
"errors"

internal/cnpgi/instance/start.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
99
"google.golang.org/grpc"
1010
"sigs.k8s.io/controller-runtime/pkg/client"
11+
12+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
1113
)
1214

1315
// CNPGI is the implementation of the PostgreSQL sidecar
@@ -26,7 +28,7 @@ type CNPGI struct {
2628
// Start starts the GRPC service
2729
func (c *CNPGI) Start(ctx context.Context) error {
2830
enrich := func(server *grpc.Server) error {
29-
wal.RegisterWALServer(server, WALServiceImplementation{
31+
wal.RegisterWALServer(server, common.WALServiceImplementation{
3032
BarmanObjectKey: c.BarmanObjectKey,
3133
ClusterObjectKey: c.ClusterObjectKey,
3234
InstanceName: c.InstanceName,

internal/cnpgi/restore/manager.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func Start(ctx context.Context) error {
3333
setupLog.Info("Starting barman cloud instance plugin")
3434
namespace := viper.GetString("namespace")
3535
clusterName := viper.GetString("cluster-name")
36+
boName := viper.GetString("barman-object-name")
3637

3738
objs := map[client.Object]cache.ByObject{
3839
&cnpgv1.Cluster{}: {
@@ -43,6 +44,15 @@ func Start(ctx context.Context) error {
4344
},
4445
}
4546

47+
if boName != "" {
48+
objs[&barmancloudv1.ObjectStore{}] = cache.ByObject{
49+
Field: fields.OneTermEqualSelector("metadata.name", boName),
50+
Namespaces: map[string]cache.Config{
51+
namespace: {},
52+
},
53+
}
54+
}
55+
4656
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
4757
Scheme: scheme,
4858
Cache: cache.Options{
@@ -65,12 +75,17 @@ func Start(ctx context.Context) error {
6575
if err := mgr.Add(&CNPGI{
6676
PluginPath: viper.GetString("plugin-path"),
6777
SpoolDirectory: viper.GetString("spool-directory"),
78+
BarmanObjectKey: client.ObjectKey{
79+
Namespace: namespace,
80+
Name: boName,
81+
},
6882
ClusterObjectKey: client.ObjectKey{
6983
Namespace: namespace,
7084
Name: clusterName,
7185
},
72-
Client: mgr.GetClient(),
73-
PGDataPath: viper.GetString("pgdata"),
86+
Client: mgr.GetClient(),
87+
PGDataPath: viper.GetString("pgdata"),
88+
InstanceName: viper.GetString("pod-name"),
7489
}); err != nil {
7590
setupLog.Error(err, "unable to create CNPGI runnable")
7691
return err

internal/cnpgi/restore/restore.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
8+
"os/exec"
9+
"path"
10+
711
"github.com/cloudnative-pg/barman-cloud/pkg/api"
812
barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
913
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
@@ -21,9 +25,6 @@ import (
2125
"github.com/cloudnative-pg/machinery/pkg/log"
2226
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2327
"k8s.io/apimachinery/pkg/types"
24-
"os"
25-
"os/exec"
26-
"path"
2728
"sigs.k8s.io/controller-runtime/pkg/client"
2829

2930
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"

internal/cnpgi/restore/start.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@ package restore
22

33
import (
44
"context"
5+
"path"
56

67
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper/http"
78
restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
9+
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
810
"google.golang.org/grpc"
911
"sigs.k8s.io/controller-runtime/pkg/client"
12+
13+
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
1014
)
1115

1216
// CNPGI is the implementation of the PostgreSQL sidecar
1317
type CNPGI struct {
1418
PluginPath string
1519
SpoolDirectory string
20+
BarmanObjectKey client.ObjectKey
1621
ClusterObjectKey client.ObjectKey
1722
Client client.Client
1823
PGDataPath string
24+
InstanceName string
1925
}
2026

2127
// Start starts the GRPC service
@@ -24,6 +30,16 @@ func (c *CNPGI) Start(ctx context.Context) error {
2430
const PgWalVolumePgWalPath = "/var/lib/postgresql/wal/pg_wal"
2531

2632
enrich := func(server *grpc.Server) error {
33+
wal.RegisterWALServer(server, common.WALServiceImplementation{
34+
BarmanObjectKey: c.BarmanObjectKey,
35+
ClusterObjectKey: c.ClusterObjectKey,
36+
InstanceName: c.InstanceName,
37+
Client: c.Client,
38+
SpoolDirectory: c.SpoolDirectory,
39+
PGDataPath: c.PGDataPath,
40+
PGWALPath: path.Join(c.PGDataPath, "pg_wal"),
41+
})
42+
2743
restore.RegisterRestoreJobHooksServer(server, &JobHookImpl{
2844
Client: c.Client,
2945
ClusterObjectKey: c.ClusterObjectKey,

0 commit comments

Comments
 (0)