Skip to content

Commit b0a0dca

Browse files
committed
chore: review
Signed-off-by: Marco Nenciarini <[email protected]>
1 parent 6ac904a commit b0a0dca

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

internal/cnpgi/instance/retention.go

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
// defaultRetentionPolicyInterval is the retention policy interval
28-
// that is used when the current cluster or barman object store can't
28+
// used when the current cluster or barman object store can't
2929
// be read or when the enforcement process failed
3030
const defaultRetentionPolicyInterval = time.Minute * 5
3131

@@ -38,7 +38,7 @@ type RetentionPolicyRunnable struct {
3838
CurrentPodName string
3939
}
4040

41-
// Start enforce the backup retention policies periodically, using the
41+
// Start enforces the backup retention policies periodically, using the
4242
// period specified in the BarmanObjectStore object
4343
func (c *RetentionPolicyRunnable) Start(ctx context.Context) error {
4444
contextLogger := log.FromContext(ctx)
@@ -55,14 +55,10 @@ func (c *RetentionPolicyRunnable) Start(ctx context.Context) error {
5555
period = defaultRetentionPolicyInterval
5656
}
5757

58-
// Wait before running another cycle
59-
t := time.NewTimer(period)
60-
defer t.Stop()
61-
6258
select {
59+
case <-time.After(period):
6360
case <-ctx.Done():
6461
return nil
65-
case <-t.C:
6662
}
6763
}
6864
}
@@ -102,21 +98,13 @@ func (c *RetentionPolicyRunnable) applyRetentionPolicy(
10298
configuration := config.NewFromCluster(cluster)
10399
retentionPolicy := objectStore.Spec.RetentionPolicy
104100

105-
if len(retentionPolicy) == 0 {
106-
contextLogger.Info("Skipping retention policy enforcement, no retention policy specified")
107-
return nil
108-
}
109-
110101
if cluster.Status.CurrentPrimary != c.CurrentPodName {
111102
contextLogger.Info(
112103
"Skipping retention policy enforcement, not the current primary",
113104
"currentPrimary", cluster.Status.CurrentPrimary, "podName", c.CurrentPodName)
114105
return nil
115106
}
116107

117-
contextLogger.Info("Applying backup retention policy",
118-
"retentionPolicy", retentionPolicy)
119-
120108
env, err := barmanCredentials.EnvSetBackupCloudCredentials(
121109
ctx,
122110
c.Client,
@@ -128,16 +116,23 @@ func (c *RetentionPolicyRunnable) applyRetentionPolicy(
128116
return err
129117
}
130118

131-
if err := barmanCommand.DeleteBackupsByPolicy(
132-
ctx,
133-
&objectStore.Spec.Configuration,
134-
configuration.ServerName,
135-
env,
136-
retentionPolicy,
137-
); err != nil {
138-
contextLogger.Error(err, "while enforcing retention policies")
139-
c.Recorder.Event(cluster, "Warning", "RetentionPolicyFailed", "Retention policy failed")
140-
return err
119+
if len(retentionPolicy) == 0 {
120+
contextLogger.Info("Skipping retention policy enforcement, no retention policy specified")
121+
} else {
122+
contextLogger.Info("Applying backup retention policy",
123+
"retentionPolicy", retentionPolicy)
124+
125+
if err := barmanCommand.DeleteBackupsByPolicy(
126+
ctx,
127+
&objectStore.Spec.Configuration,
128+
configuration.ServerName,
129+
env,
130+
retentionPolicy,
131+
); err != nil {
132+
contextLogger.Error(err, "while enforcing retention policies")
133+
c.Recorder.Event(cluster, "Warning", "RetentionPolicyFailed", "Retention policy failed")
134+
return err
135+
}
141136
}
142137

143138
backupList, err := barmanCommand.GetBackupList(

0 commit comments

Comments
 (0)