mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-11 21:23:12 +01:00
feat: add wal-restore capabilities during restore
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
0141ff33ab
commit
cacf3fdfcb
@ -1,4 +1,4 @@
|
||||
package instance
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -19,7 +19,6 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||
)
|
||||
|
||||
@ -152,7 +151,7 @@ func (w WALServiceImplementation) Restore(
|
||||
|
||||
barmanConfiguration := &objectStore.Spec.Configuration
|
||||
|
||||
env := common.GetRestoreCABundleEnv(barmanConfiguration)
|
||||
env := GetRestoreCABundleEnv(barmanConfiguration)
|
||||
credentialsEnv, err := barmanCredentials.EnvSetBackupCloudCredentials(
|
||||
ctx,
|
||||
w.Client,
|
||||
@ -163,7 +162,7 @@ func (w WALServiceImplementation) Restore(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("while getting recover credentials: %w", err)
|
||||
}
|
||||
env = common.MergeEnv(env, credentialsEnv)
|
||||
env = MergeEnv(env, credentialsEnv)
|
||||
|
||||
// TODO: refactor this code elsewhere
|
||||
serverName := cluster.Name
|
||||
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package instance
|
||||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -8,6 +8,8 @@ import (
|
||||
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
|
||||
"google.golang.org/grpc"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
|
||||
)
|
||||
|
||||
// CNPGI is the implementation of the PostgreSQL sidecar
|
||||
@ -26,7 +28,7 @@ type CNPGI struct {
|
||||
// Start starts the GRPC service
|
||||
func (c *CNPGI) Start(ctx context.Context) error {
|
||||
enrich := func(server *grpc.Server) error {
|
||||
wal.RegisterWALServer(server, WALServiceImplementation{
|
||||
wal.RegisterWALServer(server, common.WALServiceImplementation{
|
||||
BarmanObjectKey: c.BarmanObjectKey,
|
||||
ClusterObjectKey: c.ClusterObjectKey,
|
||||
InstanceName: c.InstanceName,
|
||||
|
||||
@ -33,6 +33,7 @@ func Start(ctx context.Context) error {
|
||||
setupLog.Info("Starting barman cloud instance plugin")
|
||||
namespace := viper.GetString("namespace")
|
||||
clusterName := viper.GetString("cluster-name")
|
||||
boName := viper.GetString("barman-object-name")
|
||||
|
||||
objs := map[client.Object]cache.ByObject{
|
||||
&cnpgv1.Cluster{}: {
|
||||
@ -43,6 +44,15 @@ func Start(ctx context.Context) error {
|
||||
},
|
||||
}
|
||||
|
||||
if boName != "" {
|
||||
objs[&barmancloudv1.ObjectStore{}] = cache.ByObject{
|
||||
Field: fields.OneTermEqualSelector("metadata.name", boName),
|
||||
Namespaces: map[string]cache.Config{
|
||||
namespace: {},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||
Scheme: scheme,
|
||||
Cache: cache.Options{
|
||||
@ -65,12 +75,17 @@ func Start(ctx context.Context) error {
|
||||
if err := mgr.Add(&CNPGI{
|
||||
PluginPath: viper.GetString("plugin-path"),
|
||||
SpoolDirectory: viper.GetString("spool-directory"),
|
||||
BarmanObjectKey: client.ObjectKey{
|
||||
Namespace: namespace,
|
||||
Name: boName,
|
||||
},
|
||||
ClusterObjectKey: client.ObjectKey{
|
||||
Namespace: namespace,
|
||||
Name: clusterName,
|
||||
},
|
||||
Client: mgr.GetClient(),
|
||||
PGDataPath: viper.GetString("pgdata"),
|
||||
Client: mgr.GetClient(),
|
||||
PGDataPath: viper.GetString("pgdata"),
|
||||
InstanceName: viper.GetString("pod-name"),
|
||||
}); err != nil {
|
||||
setupLog.Error(err, "unable to create CNPGI runnable")
|
||||
return err
|
||||
|
||||
@ -4,6 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
||||
"github.com/cloudnative-pg/barman-cloud/pkg/api"
|
||||
barmanArchiver "github.com/cloudnative-pg/barman-cloud/pkg/archiver"
|
||||
barmanCapabilities "github.com/cloudnative-pg/barman-cloud/pkg/capabilities"
|
||||
@ -21,9 +25,6 @@ import (
|
||||
"github.com/cloudnative-pg/machinery/pkg/log"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
|
||||
|
||||
@ -2,20 +2,26 @@ package restore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
|
||||
"github.com/cloudnative-pg/cnpg-i-machinery/pkg/pluginhelper/http"
|
||||
restore "github.com/cloudnative-pg/cnpg-i/pkg/restore/job"
|
||||
"github.com/cloudnative-pg/cnpg-i/pkg/wal"
|
||||
"google.golang.org/grpc"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
|
||||
)
|
||||
|
||||
// CNPGI is the implementation of the PostgreSQL sidecar
|
||||
type CNPGI struct {
|
||||
PluginPath string
|
||||
SpoolDirectory string
|
||||
BarmanObjectKey client.ObjectKey
|
||||
ClusterObjectKey client.ObjectKey
|
||||
Client client.Client
|
||||
PGDataPath string
|
||||
InstanceName string
|
||||
}
|
||||
|
||||
// Start starts the GRPC service
|
||||
@ -24,6 +30,16 @@ func (c *CNPGI) Start(ctx context.Context) error {
|
||||
const PgWalVolumePgWalPath = "/var/lib/postgresql/wal/pg_wal"
|
||||
|
||||
enrich := func(server *grpc.Server) error {
|
||||
wal.RegisterWALServer(server, common.WALServiceImplementation{
|
||||
BarmanObjectKey: c.BarmanObjectKey,
|
||||
ClusterObjectKey: c.ClusterObjectKey,
|
||||
InstanceName: c.InstanceName,
|
||||
Client: c.Client,
|
||||
SpoolDirectory: c.SpoolDirectory,
|
||||
PGDataPath: c.PGDataPath,
|
||||
PGWALPath: path.Join(c.PGDataPath, "pg_wal"),
|
||||
})
|
||||
|
||||
restore.RegisterRestoreJobHooksServer(server, &JobHookImpl{
|
||||
Client: c.Client,
|
||||
ClusterObjectKey: c.ClusterObjectKey,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user