Skip to content

Commit

Permalink
If no etcd was deployed, fail etcd-snapshot with a useful error
Browse files Browse the repository at this point in the history
Signed-off-by: manuelbuil <[email protected]>
  • Loading branch information
manuelbuil committed Nov 13, 2024
1 parent b93fd98 commit 17234f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 16 additions & 0 deletions pkg/cli/etcdsnapshot/etcd_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions tests/e2e/snapshotrestore/snapshotrestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 17234f0

Please sign in to comment.