mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 05:33:11 +01:00
chore: review
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
This commit is contained in:
parent
027ddf1276
commit
1634495c31
@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// defaultRetentionPolicyInterval is the retention policy interval
|
// defaultRetentionPolicyInterval is the retention policy interval
|
||||||
// that is used when the current cluster or barman object store can't
|
// used when the current cluster or barman object store can't
|
||||||
// be read or when the enforcement process failed
|
// be read or when the enforcement process failed
|
||||||
const defaultRetentionPolicyInterval = time.Minute * 5
|
const defaultRetentionPolicyInterval = time.Minute * 5
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ type RetentionPolicyRunnable struct {
|
|||||||
CurrentPodName string
|
CurrentPodName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start enforce the backup retention policies periodically, using the
|
// Start enforces the backup retention policies periodically, using the
|
||||||
// period specified in the BarmanObjectStore object
|
// period specified in the BarmanObjectStore object
|
||||||
func (c *RetentionPolicyRunnable) Start(ctx context.Context) error {
|
func (c *RetentionPolicyRunnable) Start(ctx context.Context) error {
|
||||||
contextLogger := log.FromContext(ctx)
|
contextLogger := log.FromContext(ctx)
|
||||||
@ -55,14 +55,10 @@ func (c *RetentionPolicyRunnable) Start(ctx context.Context) error {
|
|||||||
period = defaultRetentionPolicyInterval
|
period = defaultRetentionPolicyInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait before running another cycle
|
|
||||||
t := time.NewTimer(period)
|
|
||||||
defer t.Stop()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
case <-time.After(period):
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil
|
return nil
|
||||||
case <-t.C:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,11 +98,6 @@ func (c *RetentionPolicyRunnable) applyRetentionPolicy(
|
|||||||
configuration := config.NewFromCluster(cluster)
|
configuration := config.NewFromCluster(cluster)
|
||||||
retentionPolicy := objectStore.Spec.RetentionPolicy
|
retentionPolicy := objectStore.Spec.RetentionPolicy
|
||||||
|
|
||||||
if len(retentionPolicy) == 0 {
|
|
||||||
contextLogger.Info("Skipping retention policy enforcement, no retention policy specified")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if cluster.Status.CurrentPrimary != c.CurrentPodName {
|
if cluster.Status.CurrentPrimary != c.CurrentPodName {
|
||||||
contextLogger.Info(
|
contextLogger.Info(
|
||||||
"Skipping retention policy enforcement, not the current primary",
|
"Skipping retention policy enforcement, not the current primary",
|
||||||
@ -114,9 +105,6 @@ func (c *RetentionPolicyRunnable) applyRetentionPolicy(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
contextLogger.Info("Applying backup retention policy",
|
|
||||||
"retentionPolicy", retentionPolicy)
|
|
||||||
|
|
||||||
env, err := barmanCredentials.EnvSetBackupCloudCredentials(
|
env, err := barmanCredentials.EnvSetBackupCloudCredentials(
|
||||||
ctx,
|
ctx,
|
||||||
c.Client,
|
c.Client,
|
||||||
@ -128,16 +116,23 @@ func (c *RetentionPolicyRunnable) applyRetentionPolicy(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := barmanCommand.DeleteBackupsByPolicy(
|
if len(retentionPolicy) == 0 {
|
||||||
ctx,
|
contextLogger.Info("Skipping retention policy enforcement, no retention policy specified")
|
||||||
&objectStore.Spec.Configuration,
|
} else {
|
||||||
configuration.ServerName,
|
contextLogger.Info("Applying backup retention policy",
|
||||||
env,
|
"retentionPolicy", retentionPolicy)
|
||||||
retentionPolicy,
|
|
||||||
); err != nil {
|
if err := barmanCommand.DeleteBackupsByPolicy(
|
||||||
contextLogger.Error(err, "while enforcing retention policies")
|
ctx,
|
||||||
c.Recorder.Event(cluster, "Warning", "RetentionPolicyFailed", "Retention policy failed")
|
&objectStore.Spec.Configuration,
|
||||||
return err
|
configuration.ServerName,
|
||||||
|
env,
|
||||||
|
retentionPolicy,
|
||||||
|
); err != nil {
|
||||||
|
contextLogger.Error(err, "while enforcing retention policies")
|
||||||
|
c.Recorder.Event(cluster, "Warning", "RetentionPolicyFailed", "Retention policy failed")
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
backupList, err := barmanCommand.GetBackupList(
|
backupList, err := barmanCommand.GetBackupList(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user