Merge branch 'k3s-io:master' into issue-backport

This commit is contained in:
Chris Wayne 2021-07-19 17:32:31 -04:00 committed by GitHub
commit f7e86115a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -41,7 +41,6 @@ import (
) )
const ( const (
snapshotPrefix = "etcd-snapshot-"
endpoint = "https://127.0.0.1:2379" endpoint = "https://127.0.0.1:2379"
testTimeout = time.Second * 10 testTimeout = time.Second * 10
manageTickerTime = time.Second * 15 manageTickerTime = time.Second * 15
@ -854,7 +853,7 @@ func (e *ETCD) Snapshot(ctx context.Context, config *config.Control) error {
// check if we need to perform a retention check // check if we need to perform a retention check
if e.config.EtcdSnapshotRetention >= 1 { if e.config.EtcdSnapshotRetention >= 1 {
if err := snapshotRetention(e.config.EtcdSnapshotRetention, snapshotDir); err != nil { if err := snapshotRetention(e.config.EtcdSnapshotRetention, e.config.EtcdSnapshotName, snapshotDir); err != nil {
return errors.Wrap(err, "failed to apply snapshot retention") return errors.Wrap(err, "failed to apply snapshot retention")
} }
} }
@ -986,7 +985,7 @@ func (e *ETCD) PruneSnapshots(ctx context.Context) error {
return e.s3.snapshotRetention(ctx) return e.s3.snapshotRetention(ctx)
} }
return snapshotRetention(e.config.EtcdSnapshotRetention, snapshotDir) return snapshotRetention(e.config.EtcdSnapshotRetention, e.config.EtcdSnapshotName, snapshotDir)
} }
// ListSnapshots is an exported wrapper method that wraps an // ListSnapshots is an exported wrapper method that wraps an
@ -1206,7 +1205,7 @@ func (e *ETCD) Restore(ctx context.Context) error {
// snapshotRetention iterates through the snapshots and removes the oldest // snapshotRetention iterates through the snapshots and removes the oldest
// leaving the desired number of snapshots. // leaving the desired number of snapshots.
func snapshotRetention(retention int, snapshotDir string) error { func snapshotRetention(retention int, snapshotPrefix string, snapshotDir string) error {
nodeName := os.Getenv("NODE_NAME") nodeName := os.Getenv("NODE_NAME")
var snapshotFiles []os.FileInfo var snapshotFiles []os.FileInfo
@ -1214,7 +1213,7 @@ func snapshotRetention(retention int, snapshotDir string) error {
if err != nil { if err != nil {
return err return err
} }
if strings.HasPrefix(info.Name(), snapshotPrefix+nodeName) { if strings.HasPrefix(info.Name(), snapshotPrefix+"-"+nodeName) {
snapshotFiles = append(snapshotFiles, info) snapshotFiles = append(snapshotFiles, info)
} }
return nil return nil

View File

@ -157,7 +157,7 @@ func (s *S3) Download(ctx context.Context) error {
// naming of the snapshots. // naming of the snapshots.
func (s *S3) snapshotPrefix() string { func (s *S3) snapshotPrefix() string {
nodeName := os.Getenv("NODE_NAME") nodeName := os.Getenv("NODE_NAME")
fullSnapshotPrefix := snapshotPrefix + nodeName fullSnapshotPrefix := s.config.EtcdSnapshotName + "-" + nodeName
var prefix string var prefix string
if s.config.EtcdS3Folder != "" { if s.config.EtcdS3Folder != "" {
prefix = filepath.Join(s.config.EtcdS3Folder, fullSnapshotPrefix) prefix = filepath.Join(s.config.EtcdS3Folder, fullSnapshotPrefix)