From 9c77e3de9f05a56c567c9fa6b0f75ca55a05ddf8 Mon Sep 17 00:00:00 2001 From: Leonardo Cecchi Date: Fri, 22 Nov 2024 16:35:01 +0100 Subject: [PATCH] fix: avoid injecting the plugin environment into the PG container (#62) Signed-off-by: Leonardo Cecchi --- internal/cnpgi/operator/config/config.go | 42 ++++++++++++++++++++---- internal/cnpgi/restore/restore.go | 2 +- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/internal/cnpgi/operator/config/config.go b/internal/cnpgi/operator/config/config.go index 1b28923..53e0de3 100644 --- a/internal/cnpgi/operator/config/config.go +++ b/internal/cnpgi/operator/config/config.go @@ -44,7 +44,9 @@ func (e *ConfigurationError) IsEmpty() bool { // PluginConfiguration is the configuration of the plugin type PluginConfiguration struct { - BarmanObjectName string + BarmanObjectName string + RecoveryBarmanObjectName string + RecoveryBarmanServerName string } // NewFromCluster extracts the configuration from the cluster @@ -54,22 +56,50 @@ func NewFromCluster(cluster *cnpgv1.Cluster) *PluginConfiguration { metadata.PluginName, ) + recoveryServerName := "" + recoveryBarmanObjectName := "" + + if recoveryParameters := getRecoveryParameters(cluster); recoveryParameters != nil { + recoveryBarmanObjectName = recoveryParameters["barmanObjectName"] + recoveryServerName = recoveryParameters["serverName"] + if len(recoveryServerName) == 0 { + recoveryServerName = cluster.Name + } + } + result := &PluginConfiguration{ // used for the backup/archive BarmanObjectName: helper.Parameters["barmanObjectName"], + // used for restore/wal_restore + RecoveryBarmanServerName: recoveryServerName, + RecoveryBarmanObjectName: recoveryBarmanObjectName, } return result } -// Validate checks if the barmanObjectName is set -func (p *PluginConfiguration) Validate() error { - err := NewConfigurationError() - if len(p.BarmanObjectName) != 0 { +func getRecoveryParameters(cluster *cnpgv1.Cluster) map[string]string { + recoveryPluginConfiguration := cluster.GetRecoverySourcePlugin() + if recoveryPluginConfiguration == nil { return nil } - return err.WithMessage("Missing barmanObjectName parameter") + if recoveryPluginConfiguration.Name != metadata.PluginName { + return nil + } + + return recoveryPluginConfiguration.Parameters +} + +// Validate checks if the barmanObjectName is set +func (p *PluginConfiguration) Validate() error { + err := NewConfigurationError() + + if len(p.BarmanObjectName) == 0 && len(p.RecoveryBarmanObjectName) == 0 { + return err.WithMessage("no reference to barmanObjectName have been included") + } + + return nil } // Plugin represents a plugin with its associated cluster and parameters. diff --git a/internal/cnpgi/restore/restore.go b/internal/cnpgi/restore/restore.go index 9029156..4ad1745 100644 --- a/internal/cnpgi/restore/restore.go +++ b/internal/cnpgi/restore/restore.go @@ -160,7 +160,7 @@ func (impl JobHookImpl) Restore( contextLogger.Info("sending restore response", "config", config, "env", env) return &restore.RestoreResponse{ RestoreConfig: config, - Envs: env, + Envs: nil, }, nil }