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

Add snapshot retention etcd-s3-folder fix #10293

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/etcd/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/s3/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * * *'
brandond marked this conversation as resolved.
Show resolved Hide resolved
etcd-snapshot-retention: 2
etcd-s3-insecure: true
etcd-s3-bucket: test-bucket
etcd-s3-folder: test-folder
Expand Down
11 changes: 10 additions & 1 deletion tests/e2e/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"strings"
"testing"
"time"

"github.com/k3s-io/k3s/tests/e2e"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -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"))
})
})
})

Expand Down