Skip to content

Commit f1a5e1c

Browse files
Minor refactor in backup inttest
Add -d to make things easier to troubleshoot, remove redundant checks, fix typos and make some checks slightly shorter. Signed-off-by: Juan-Luis de Sousa-Valadas Castaño <[email protected]>
1 parent a5866e5 commit f1a5e1c

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

inttest/backup/backup_test.go

+11-22
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,8 @@ func (s *BackupSuite) TestK0sGetsUp() {
7676
s.Require().NoError(s.InitController(1, token, "--config=/tmp/k0s.yaml"))
7777
s.Require().NoError(s.WaitJoinAPI(s.ControllerNode(1)))
7878

79-
err = s.WaitForNodeReady(s.WorkerNode(0), kc)
80-
s.Require().NoError(err)
81-
82-
err = s.WaitForNodeReady(s.WorkerNode(1), kc)
83-
s.Require().NoError(err)
79+
s.Require().NoError(s.WaitForNodeReady(s.WorkerNode(0), kc))
80+
s.Require().NoError(s.WaitForNodeReady(s.WorkerNode(1), kc))
8481

8582
s.AssertSomeKubeSystemPods(kc)
8683

@@ -91,8 +88,6 @@ func (s *BackupSuite) TestK0sGetsUp() {
9188

9289
snapshot := s.makeSnapshot(kc)
9390

94-
s.Require().NoError(err)
95-
9691
s.Require().NoError(s.StopController(s.ControllerNode(0)))
9792
_ = s.StopController(s.ControllerNode(1)) // No error check as k0s might have actually exited since etcd is not really happy
9893

@@ -106,16 +101,10 @@ func (s *BackupSuite) TestK0sGetsUp() {
106101
// Join the second controller as normally
107102
s.Require().NoError(s.InitController(1, "--enable-worker", token))
108103

109-
s.Require().NoError(err)
110-
111-
err = s.WaitForNodeReady(s.WorkerNode(0), kc)
112-
s.Require().NoError(err)
113-
114-
err = s.WaitForNodeReady(s.WorkerNode(1), kc)
115-
s.Require().NoError(err)
104+
s.Require().NoError(s.WaitForNodeReady(s.WorkerNode(0), kc))
105+
s.Require().NoError(s.WaitForNodeReady(s.WorkerNode(1), kc))
116106

117107
snapshotAfterBackup := s.makeSnapshot(kc)
118-
s.Require().NoError(err)
119108
// Matching object UIDs after restore guarantees we got the full state restored
120109
s.Require().Equal(snapshot, snapshotAfterBackup)
121110

@@ -191,7 +180,7 @@ func (s *BackupSuite) takeBackup() error {
191180
}
192181
defer ssh.Disconnect()
193182

194-
out, err := ssh.ExecWithOutput(s.Context(), "/usr/local/bin/k0s backup --save-path /root/")
183+
out, err := ssh.ExecWithOutput(s.Context(), "/usr/local/bin/k0s backup --debug --save-path /root/")
195184
if !s.NoErrorf(err, "backup failed with output: %s", out) {
196185
return err
197186
}
@@ -206,7 +195,7 @@ func (s *BackupSuite) takeBackupStdout() error {
206195
}
207196
defer ssh.Disconnect()
208197

209-
out, err := ssh.ExecWithOutput(s.Context(), "/usr/local/bin/k0s backup --save-path - > backup.tar.gz")
198+
out, err := ssh.ExecWithOutput(s.Context(), "/usr/local/bin/k0s backup --debug --save-path - > backup.tar.gz")
210199
if !s.NoErrorf(err, "backup failed with output: %s", out) {
211200
return err
212201
}
@@ -216,7 +205,7 @@ func (s *BackupSuite) takeBackupStdout() error {
216205
return err
217206
}
218207

219-
s.T().Logf("backup taken succesfully with output:\n%s", out)
208+
s.T().Logf("backup taken successfully with output:\n%s", out)
220209
return nil
221210
}
222211

@@ -229,11 +218,11 @@ func (s *BackupSuite) restoreBackup() error {
229218

230219
s.T().Log("restoring controller from file")
231220

232-
out, err := ssh.ExecWithOutput(s.Context(), "/usr/local/bin/k0s restore $(ls /root/k0s_backup_*.tar.gz)")
221+
out, err := ssh.ExecWithOutput(s.Context(), "/usr/local/bin/k0s restore --debug $(ls /root/k0s_backup_*.tar.gz)")
233222
if !s.NoErrorf(err, "restore failed with output: %s", out) {
234223
return err
235224
}
236-
s.T().Logf("restored succesfully with output:\n%s", out)
225+
s.T().Logf("restored successfully with output:\n%s", out)
237226

238227
return nil
239228
}
@@ -247,11 +236,11 @@ func (s *BackupSuite) restoreBackupStdin() error {
247236

248237
s.T().Log("restoring controller from stdin")
249238

250-
out, err := ssh.ExecWithOutput(s.Context(), "cat backup.tar.gz | /usr/local/bin/k0s restore -")
239+
out, err := ssh.ExecWithOutput(s.Context(), "cat backup.tar.gz | /usr/local/bin/k0s restore --debug -")
251240
if !s.NoErrorf(err, "restore failed with output: %s", out) {
252241
return err
253242
}
254-
s.T().Logf("restored succesfully with output:\n%s", out)
243+
s.T().Logf("restored successfully with output:\n%s", out)
255244

256245
return nil
257246
}

0 commit comments

Comments
 (0)