Skip to content

Commit 9c77e3d

Browse files
authored
fix: avoid injecting the plugin environment into the PG container (#62)
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent c639af1 commit 9c77e3d

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

internal/cnpgi/operator/config/config.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func (e *ConfigurationError) IsEmpty() bool {
4444

4545
// PluginConfiguration is the configuration of the plugin
4646
type PluginConfiguration struct {
47-
BarmanObjectName string
47+
BarmanObjectName string
48+
RecoveryBarmanObjectName string
49+
RecoveryBarmanServerName string
4850
}
4951

5052
// NewFromCluster extracts the configuration from the cluster
@@ -54,22 +56,50 @@ func NewFromCluster(cluster *cnpgv1.Cluster) *PluginConfiguration {
5456
metadata.PluginName,
5557
)
5658

59+
recoveryServerName := ""
60+
recoveryBarmanObjectName := ""
61+
62+
if recoveryParameters := getRecoveryParameters(cluster); recoveryParameters != nil {
63+
recoveryBarmanObjectName = recoveryParameters["barmanObjectName"]
64+
recoveryServerName = recoveryParameters["serverName"]
65+
if len(recoveryServerName) == 0 {
66+
recoveryServerName = cluster.Name
67+
}
68+
}
69+
5770
result := &PluginConfiguration{
5871
// used for the backup/archive
5972
BarmanObjectName: helper.Parameters["barmanObjectName"],
73+
// used for restore/wal_restore
74+
RecoveryBarmanServerName: recoveryServerName,
75+
RecoveryBarmanObjectName: recoveryBarmanObjectName,
6076
}
6177

6278
return result
6379
}
6480

81+
func getRecoveryParameters(cluster *cnpgv1.Cluster) map[string]string {
82+
recoveryPluginConfiguration := cluster.GetRecoverySourcePlugin()
83+
if recoveryPluginConfiguration == nil {
84+
return nil
85+
}
86+
87+
if recoveryPluginConfiguration.Name != metadata.PluginName {
88+
return nil
89+
}
90+
91+
return recoveryPluginConfiguration.Parameters
92+
}
93+
6594
// Validate checks if the barmanObjectName is set
6695
func (p *PluginConfiguration) Validate() error {
6796
err := NewConfigurationError()
68-
if len(p.BarmanObjectName) != 0 {
69-
return nil
97+
98+
if len(p.BarmanObjectName) == 0 && len(p.RecoveryBarmanObjectName) == 0 {
99+
return err.WithMessage("no reference to barmanObjectName have been included")
70100
}
71101

72-
return err.WithMessage("Missing barmanObjectName parameter")
102+
return nil
73103
}
74104

75105
// Plugin represents a plugin with its associated cluster and parameters.

internal/cnpgi/restore/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (impl JobHookImpl) Restore(
160160
contextLogger.Info("sending restore response", "config", config, "env", env)
161161
return &restore.RestoreResponse{
162162
RestoreConfig: config,
163-
Envs: env,
163+
Envs: nil,
164164
}, nil
165165
}
166166

0 commit comments

Comments
 (0)