Add snapshot retention etcd-s3-folder fix

* Add snapshot retention folder fix

Signed-off-by: Vitor Savian <vitor.savian@suse.com>

* Add snapshot retention E2E test

Signed-off-by: Vitor Savian <vitor.savian@suse.com>

---------

Signed-off-by: Vitor Savian <vitor.savian@suse.com>
pull/10328/head
Vitor Savian 6 months ago committed by GitHub
parent 043b1eac5d
commit d9b8ba8d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -321,10 +321,12 @@ func (s *S3) snapshotRetention(ctx context.Context) ([]string, error) {
deleted := []string{}
for _, df := range snapshotFiles[s.config.EtcdSnapshotRetention:] {
logrus.Infof("Removing S3 snapshot: s3://%s/%s", s.config.EtcdS3BucketName, df.Key)
if err := s.deleteSnapshot(ctx, df.Key); err != nil {
key := path.Base(df.Key)
if err := s.deleteSnapshot(ctx, key); err != nil {
return deleted, err
}
deleted = append(deleted, df.Key)
deleted = append(deleted, key)
}
return deleted, nil

@ -44,6 +44,8 @@ def provision(vm, role, role_num, node_num)
node-external-ip: #{NETWORK_PREFIX}.100
flannel-iface: eth1
cluster-init: true
etcd-snapshot-schedule-cron: '*/1 * * * *'
etcd-snapshot-retention: 2
etcd-s3-insecure: true
etcd-s3-bucket: test-bucket
etcd-s3-folder: test-folder

@ -6,6 +6,7 @@ import (
"os"
"strings"
"testing"
"time"
"github.com/k3s-io/k3s/tests/e2e"
. "github.com/onsi/ginkgo/v2"
@ -126,13 +127,21 @@ var _ = Describe("Verify Create", Ordered, func() {
Expect(err).NotTo(HaveOccurred())
_, err = e2e.RunCmdOnNode("k3s etcd-snapshot save", serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())
res, err := e2e.RunCmdOnNode("k3s etcd-snapshot prune --snapshot-retention 2", serverNodeNames[0])
res, err := e2e.RunCmdOnNode("k3s etcd-snapshot prune", serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())
// There should now be 4 on-demand snapshots - 2 local, and 2 on s3
res, err = e2e.RunCmdOnNode("k3s etcd-snapshot ls 2>/dev/null | grep on-demand | wc -l", serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())
Expect(strings.TrimSpace(res)).To(Equal("4"))
})
It("ensure snapshots retention is working in s3 and local", func() {
// Wait until the retention works with 3 minutes
fmt.Printf("\nWaiting 3 minutes until retention works\n")
time.Sleep(3 * time.Minute)
res, err := e2e.RunCmdOnNode("k3s etcd-snapshot ls 2>/dev/null | grep etcd-snapshot | wc -l", serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())
Expect(strings.TrimSpace(res)).To(Equal("4"))
})
})
})

Loading…
Cancel
Save