Unverified Commit e83b1ba4 authored by Vitor Savian's avatar Vitor Savian Committed by GitHub

Fixed the etcd retention to delete orphaned snapshots based on the date (#8177)

* Fix retention using name instead of date Signed-off-by: 's avatarVitor <vitor.savian@suse.com>
parent 561db17a
......@@ -2046,8 +2046,11 @@ func snapshotRetention(retention int, snapshotPrefix string, snapshotDir string)
if len(snapshotFiles) <= retention {
return nil
}
sort.Slice(snapshotFiles, func(i, j int) bool {
return snapshotFiles[i].Name() < snapshotFiles[j].Name()
sort.Slice(snapshotFiles, func(firstSnapshot, secondSnapshot int) bool {
// it takes the name from the snapshot file ex: etcd-snapshot-example-{date}, makes the split using "-" to find the date, takes the date and sort by date
firstSnapshotName, secondSnapshotName := strings.Split(snapshotFiles[firstSnapshot].Name(), "-"), strings.Split(snapshotFiles[secondSnapshot].Name(), "-")
firstSnapshotDate, secondSnapshotDate := firstSnapshotName[len(firstSnapshotName)-1], secondSnapshotName[len(secondSnapshotName)-1]
return firstSnapshotDate < secondSnapshotDate
})
delCount := len(snapshotFiles) - retention
......
......@@ -249,8 +249,11 @@ func (s *S3) snapshotRetention(ctx context.Context) error {
return nil
}
sort.Slice(snapshotFiles, func(i, j int) bool {
return snapshotFiles[i].Key < snapshotFiles[j].Key
sort.Slice(snapshotFiles, func(firstSnapshot, secondSnapshot int) bool {
// it takes the key from the snapshot file ex: etcd-snapshot-example-{date}, makes the split using "-" to find the date, takes the date and sort by date
firstSnapshotName, secondSnapshotName := strings.Split(snapshotFiles[firstSnapshot].Key, "-"), strings.Split(snapshotFiles[secondSnapshot].Key, "-")
firstSnapshotDate, secondSnapshotDate := firstSnapshotName[len(firstSnapshotName)-1], secondSnapshotName[len(secondSnapshotName)-1]
return firstSnapshotDate < secondSnapshotDate
})
delCount := len(snapshotFiles) - s.config.EtcdSnapshotRetention
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment