diff --git a/pkg/cli/etcdsnapshot/etcd_snapshot.go b/pkg/cli/etcdsnapshot/etcd_snapshot.go index 876b0ea7dec5..0cab8e30c085 100644 --- a/pkg/cli/etcdsnapshot/etcd_snapshot.go +++ b/pkg/cli/etcdsnapshot/etcd_snapshot.go @@ -82,10 +82,26 @@ func commandSetup(app *cli.Context, cfg *cmds.Server) (*etcd.SnapshotRequest, *c } cfg.Token = string(bytes.TrimRight(tokenByte, "\n")) } + + if !etcdRunning(dataDir) { + return nil, nil, errors.New("K3s is not deployed with an etcd datastore") + } + info, err := clientaccess.ParseAndValidateToken(cmds.ServerConfig.ServerURL, cfg.Token, clientaccess.WithUser("server")) return sr, info, err } +// etcdRunning checks if etcd is the datastore +func etcdRunning(dataDir string) bool { + // if kine.sock is present and db/etcd/config is not, we are not using etcd. Only one of them missing could also mean a wrong dataDir + _, errEtcd := os.Stat(filepath.Join(dataDir, "db/etcd/config")) + _, errKine := os.Stat(filepath.Join(dataDir, "kine.sock")) + if os.IsNotExist(errEtcd) && !os.IsNotExist(errKine) { + return false + } + return true +} + func wrapServerError(err error) error { if errors.Is(err, context.DeadlineExceeded) { // if the request timed out the server log likely won't contain anything useful, diff --git a/tests/e2e/snapshotrestore/snapshotrestore_test.go b/tests/e2e/snapshotrestore/snapshotrestore_test.go index dc47907f78c7..eb5b1c6848a1 100644 --- a/tests/e2e/snapshotrestore/snapshotrestore_test.go +++ b/tests/e2e/snapshotrestore/snapshotrestore_test.go @@ -145,17 +145,6 @@ var _ = Describe("Verify snapshots and cluster restores work", Ordered, func() { Expect(e2e.RunCmdOnNode(cmd, serverNodeNames[0])).Error().NotTo(HaveOccurred()) }) - It("Resets non bootstrap nodes", func() { - for _, nodeName := range serverNodeNames { - if nodeName != serverNodeNames[0] { - cmd := "k3s server --cluster-reset" - response, err := e2e.RunCmdOnNode(cmd, nodeName) - Expect(err).NotTo(HaveOccurred()) - Expect(response).Should(ContainSubstring("Managed etcd cluster membership has been reset, restart without --cluster-reset flag now")) - } - } - }) - It("Checks that other servers are not ready", func() { fmt.Printf("\nFetching node status\n") Eventually(func(g Gomega) {