Skip to content

Commit

Permalink
Fixed the etcd retention to delete orphaned snapshots
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor <[email protected]>
  • Loading branch information
vitorsavian committed Aug 3, 2023
1 parent 7d84f0e commit 467c01c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pkg/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2029,15 +2029,14 @@ func snapshotRetention(retention int, snapshotPrefix string, snapshotDir string)
return nil
}

nodeName := os.Getenv("NODE_NAME")
logrus.Infof("Applying local snapshot retention policy: retention: %d, snapshotPrefix: %s, directory: %s", retention, snapshotPrefix+"-"+nodeName, snapshotDir)
logrus.Infof("Applying local snapshot retention policy: retention: %d, snapshotPrefix: %s, directory: %s", retention, snapshotPrefix, snapshotDir)

var snapshotFiles []os.FileInfo
if err := filepath.Walk(snapshotDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if strings.HasPrefix(info.Name(), snapshotPrefix+"-"+nodeName) {
if strings.HasPrefix(info.Name(), snapshotPrefix) {
snapshotFiles = append(snapshotFiles, info)
}
return nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/etcd/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ func (s *S3) Download(ctx context.Context) error {
// snapshotPrefix returns the prefix used in the
// naming of the snapshots.
func (s *S3) snapshotPrefix() string {
nodeName := os.Getenv("NODE_NAME")
fullSnapshotPrefix := s.config.EtcdSnapshotName + "-" + nodeName
fullSnapshotPrefix := s.config.EtcdSnapshotName
var prefix string
if s.config.EtcdS3Folder != "" {
prefix = filepath.Join(s.config.EtcdS3Folder, fullSnapshotPrefix)
Expand Down

0 comments on commit 467c01c

Please sign in to comment.