fix: avoid injecting the plugin environment into the PG container

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
This commit is contained in:
Leonardo Cecchi 2024-11-20 15:36:59 +01:00
parent c639af1295
commit 6274b19363
2 changed files with 37 additions and 7 deletions

View File

@ -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.

View File

@ -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
}