Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Aug 14, 2023
5 changes: 4 additions & 1 deletion pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,10 @@ func snapshotRetention(retention int, snapshotPrefix string, snapshotDir string)
return nil
}
sort.Slice(snapshotFiles, func(i, j int) bool {
return snapshotFiles[i].Name() < snapshotFiles[j].Name()
// it takes the key from the file ex: etcd-snapshot-example-{date}, makes the split using "-" to find the date, takes the date and sort by date
stringI, stringJ := strings.Split(snapshotFiles[i].Name(), "-"), strings.Split(snapshotFiles[j].Name(), "-")
vitorsavian marked this conversation as resolved.
Show resolved Hide resolved
dateI, dateJ := stringI[len(stringI)-1], stringJ[len(stringJ)-1]
return dateI < dateJ
})

delCount := len(snapshotFiles) - retention
Expand Down
5 changes: 4 additions & 1 deletion pkg/etcd/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ func (s *S3) snapshotRetention(ctx context.Context) error {
}

sort.Slice(snapshotFiles, func(i, j int) bool {
return snapshotFiles[i].Key < snapshotFiles[j].Key
// it takes the key from the file ex: etcd-snapshot-example-{date}, makes the split using "-" to find the date, takes the date and sort by date
stringI, stringJ := strings.Split(snapshotFiles[i].Key, "-"), strings.Split(snapshotFiles[j].Key, "-")
dateI, dateJ := stringI[len(stringI)-1], stringJ[len(stringJ)-1]
return dateI < dateJ
})

delCount := len(snapshotFiles) - s.config.EtcdSnapshotRetention
Expand Down