mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 22:22:21 +02:00
refactor: deduplicate barman object store presence check
Validate() and the instance sidecar injection condition each independently re-encoded "is any of BarmanObjectName, RecoveryBarmanObjectName or ReplicaSourceBarmanObjectName set". The injection condition had already drifted from Validate() once, missing RecoveryBarmanObjectName until this PR added it back. Extract a single HasAnyBarmanObjectStore() method so the two checks can no longer drift apart the same way again. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
This commit is contained in:
parent
4acf3b7301
commit
4f5f259ee7
@ -102,6 +102,15 @@ func (config *PluginConfiguration) GetReplicaSourceBarmanObjectKey() types.Names
|
||||
}
|
||||
}
|
||||
|
||||
// HasAnyBarmanObjectStore returns true if the configuration references at least
|
||||
// one barman object store, be it for backup/archiving, recovery, or as a
|
||||
// replica source.
|
||||
func (config *PluginConfiguration) HasAnyBarmanObjectStore() bool {
|
||||
return len(config.BarmanObjectName) > 0 ||
|
||||
len(config.RecoveryBarmanObjectName) > 0 ||
|
||||
len(config.ReplicaSourceBarmanObjectName) > 0
|
||||
}
|
||||
|
||||
// GetReferredBarmanObjectsKey gets the list of barman objects referred by this
|
||||
// plugin configuration
|
||||
func (config *PluginConfiguration) GetReferredBarmanObjectsKey() []types.NamespacedName {
|
||||
@ -263,9 +272,7 @@ func getReplicaSourcePlugin(cluster *cnpgv1.Cluster) *cnpgv1.PluginConfiguration
|
||||
func (config *PluginConfiguration) Validate() error {
|
||||
err := NewConfigurationError()
|
||||
|
||||
if len(config.BarmanObjectName) == 0 &&
|
||||
len(config.RecoveryBarmanObjectName) == 0 &&
|
||||
len(config.ReplicaSourceBarmanObjectName) == 0 {
|
||||
if !config.HasAnyBarmanObjectStore() {
|
||||
return err.WithMessage("no reference to barmanObjectName have been included")
|
||||
}
|
||||
|
||||
|
||||
@ -343,9 +343,7 @@ func reconcileInstancePod(
|
||||
// sidecar in its instance pods: the phase-0 bootstrap restore and the WAL
|
||||
// replay that follows both run inside the instance and rely on it. This
|
||||
// condition therefore mirrors what pluginConfiguration.Validate() accepts.
|
||||
if len(pluginConfiguration.BarmanObjectName) != 0 ||
|
||||
len(pluginConfiguration.RecoveryBarmanObjectName) != 0 ||
|
||||
len(pluginConfiguration.ReplicaSourceBarmanObjectName) != 0 {
|
||||
if pluginConfiguration.HasAnyBarmanObjectStore() {
|
||||
if err := reconcilePodSpec(
|
||||
cluster,
|
||||
&mutatedPod.Spec,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user