diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index b557e3ce2c..ff8014d5c7 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -1703,21 +1703,26 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error { } }() - for { - select { - case <-ctx.Done(): - logrus.Errorf("Unable to delete snapshot: %v", ctx.Err()) - return e.ReconcileSnapshotData(ctx) - case <-time.After(time.Millisecond * 100): - continue - case err, ok := <-e.s3.client.RemoveObjects(ctx, e.config.EtcdS3BucketName, objectsCh, minio.RemoveObjectsOptions{}): - if err.Err != nil { - logrus.Errorf("Unable to delete snapshot: %v", err.Err) - } - if !ok { + err = func() error { + for { + select { + case <-ctx.Done(): + logrus.Errorf("Unable to delete snapshot: %v", ctx.Err()) return e.ReconcileSnapshotData(ctx) + case <-time.After(time.Millisecond * 100): + continue + case err, ok := <-e.s3.client.RemoveObjects(ctx, e.config.EtcdS3BucketName, objectsCh, minio.RemoveObjectsOptions{}): + if err.Err != nil { + logrus.Errorf("Unable to delete snapshot: %v", err.Err) + } + if !ok { + return e.ReconcileSnapshotData(ctx) + } } } + }() + if err != nil { + return err } } diff --git a/tests/e2e/s3/s3_test.go b/tests/e2e/s3/s3_test.go index 859309693c..b52d5bc349 100644 --- a/tests/e2e/s3/s3_test.go +++ b/tests/e2e/s3/s3_test.go @@ -114,6 +114,18 @@ var _ = Describe("Verify Create", Ordered, func() { Expect(res).To(ContainSubstring("special-2-server-0")) Expect(res).To(ContainSubstring("special-3-server-0")) }) + It("delete first on-demand s3 snapshot", func() { + _, err := e2e.RunCmdOnNode("sudo k3s etcd-snapshot ls >> ./snapshotname.txt", serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) + snapshotName, err := e2e.RunCmdOnNode("grep -Eo 'on-demand-server-0-([0-9]+)' ./snapshotname.txt | sed 's/^/on-demand-server-0-/'| head -1", serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) + res, err := e2e.RunCmdOnNode("sudo k3s etcd-snapshot delete "+snapshotName, serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) + Expect(res).To(ContainSubstring("Removing the given etcd snapshot(s) from S3")) + Expect(res).To(ContainSubstring("Reconciliation of snapshot data in k3s-etcd-snapshots ConfigMap complete")) + Expect(res).To(ContainSubstring("Removing the given locally stored etcd snapshot(s)")) + }) + // TODO, there is currently a bug that prevents pruning on s3 snapshots that are not prefixed with "on-demand" // https://github.com/rancher/rke2/issues/3714 // Once fixed, ensure that the snapshots list are actually reduced to 2 diff --git a/tests/e2e/testutils.go b/tests/e2e/testutils.go index 19b79935d3..9dfe3e6d81 100644 --- a/tests/e2e/testutils.go +++ b/tests/e2e/testutils.go @@ -507,7 +507,7 @@ func GetCoverageReport(nodeNames []string) error { } } coverageFile := "coverage.out" - cmd := "go tool covdata textfmt -i " + strings.Join(covDirs, ",") + " -o " + coverageFile + cmd := "go tool covdata textfmt -i=" + strings.Join(covDirs, ",") + " -o=" + coverageFile if out, err := RunCommand(cmd); err != nil { return fmt.Errorf("failed to generate coverage report: %s, %v", out, err) }