fix for etcd-snapshot delete with --etcd-s3 flag (#8110)

k3s etcd-snapshot save --etcd-s3 ... is creating a local snapshot and uploading it to s3 while k3s etcd-snapshot delete --etcd-s3 ... was deleting the snapshot only on s3 buckets, this commit change the behavior of delete to do it locally and on s3

Signed-off-by: Ian Cardoso <osodracnai@gmail.com>
pull/8147/head
Ian Cardoso 2023-08-04 14:26:32 -03:00 committed by GitHub
parent 45bc26309f
commit e551308db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View File

@ -1703,6 +1703,7 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
} }
}() }()
err = func() error {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -1719,6 +1720,10 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
} }
} }
} }
}()
if err != nil {
return err
}
} }
logrus.Info("Removing the given locally stored etcd snapshot(s)") logrus.Info("Removing the given locally stored etcd snapshot(s)")

View File

@ -114,6 +114,18 @@ var _ = Describe("Verify Create", Ordered, func() {
Expect(res).To(ContainSubstring("special-2-server-0")) Expect(res).To(ContainSubstring("special-2-server-0"))
Expect(res).To(ContainSubstring("special-3-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" // 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 // https://github.com/rancher/rke2/issues/3714
// Once fixed, ensure that the snapshots list are actually reduced to 2 // Once fixed, ensure that the snapshots list are actually reduced to 2

View File

@ -507,7 +507,7 @@ func GetCoverageReport(nodeNames []string) error {
} }
} }
coverageFile := "coverage.out" 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 { if out, err := RunCommand(cmd); err != nil {
return fmt.Errorf("failed to generate coverage report: %s, %v", out, err) return fmt.Errorf("failed to generate coverage report: %s, %v", out, err)
} }