Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add host preflights for all needed ports #1205

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions cmd/embedded-cluster/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ var resetCommand = &cli.Command{
Usage: "Disable interactive prompts",
Value: false,
},
&cli.BoolFlag{
ricardomaraschini marked this conversation as resolved.
Show resolved Hide resolved
Name: "reboot",
Usage: "Reboot system after resetting the node",
Value: false,
},
},
Usage: fmt.Sprintf("Remove %s from the current node", binName),
Action: func(c *cli.Context) error {
Expand All @@ -378,7 +373,7 @@ var resetCommand = &cli.Command{
}

logrus.Info("This will remove this node from the cluster and completely reset it, removing all data stored on the node.")
logrus.Info("Do not reset another node until this is complete.")
logrus.Info("This action will cause the node to reboot. Do not reset another node until this is complete.")
if !c.Bool("force") && !c.Bool("no-prompt") && !prompts.New().Confirm("Do you want to continue?", false) {
return fmt.Errorf("Aborting")
}
Expand Down Expand Up @@ -449,10 +444,6 @@ var resetCommand = &cli.Command{
return err
}

if !c.Bool("reboot") {
logrus.Infof("Node has been reset. Please reboot to ensure transient configuration is also reset.")
}

if err := helpers.RemoveAll(defaults.PathToK0sConfig()); err != nil {
return fmt.Errorf("failed to remove k0s config: %w", err)
}
Expand Down Expand Up @@ -501,10 +492,8 @@ var resetCommand = &cli.Command{
return fmt.Errorf("failed to remove k0s binary: %w", err)
}

if c.Bool("reboot") {
if _, err := exec.Command("reboot").Output(); err != nil {
return err
}
if _, err := exec.Command("reboot").Output(); err != nil {
return err
}

return nil
Expand Down
6 changes: 6 additions & 0 deletions e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ func TestResetAndReinstall(t *testing.T) {
t.Fatalf("fail to reset the installation: %v", err)
}

t.Logf("%s: waiting for nodes to reboot", time.Now().Format(time.RFC3339))
time.Sleep(30 * time.Second)

t.Logf("%s: installing embedded-cluster on node 0 after reset", time.Now().Format(time.RFC3339))
line = []string{"single-node-install.sh", "ui"}
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
Expand Down Expand Up @@ -698,6 +701,9 @@ func TestResetAndReinstallAirgap(t *testing.T) {
t.Fatalf("fail to reset the installation: %v", err)
}

t.Logf("%s: waiting for nodes to reboot", time.Now().Format(time.RFC3339))
time.Sleep(30 * time.Second)

t.Logf("%s: installing embedded-cluster on node 0", time.Now().Format(time.RFC3339))
line = []string{"single-node-airgap-install.sh"}
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
Expand Down
45 changes: 40 additions & 5 deletions e2e/preflights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ func TestPreflights(t *testing.T) {
})

_, stderr, err := container.Exec(cli,
"apt-get update && apt-get install -y apt-utils kmod",
"apt-get update && apt-get install -y apt-utils kmod netcat-traditional",
)
if err != nil {
t.Fatalf("failed to install deps: err=%v, stderr=%s", err, stderr)
}

if _, stderr, err = container.Exec(cli, "nohup netcat -l -p 10250 &"); err != nil {
t.Fatalf("failed to start netcat: err=%v, stderr=%s", err, stderr)
}

if _, stderr, err = container.Exec(cli, "nohup netcat -l 127.0.0.1 -p 50000 &"); err != nil {
t.Fatalf("failed to start netcat: err=%v, stderr=%s", err, stderr)
}

if _, stderr, err = container.Exec(cli, "nohup netcat -l -u -p 4789 &"); err != nil {
t.Fatalf("failed to start netcat: err=%v, stderr=%s", err, stderr)
}

runCmd := fmt.Sprintf("%s install run-preflights --no-prompt", container.GetECBinaryPath())
if os.Getenv("LICENSE_PATH") != "" {
runCmd = fmt.Sprintf("%s --license %s", runCmd, container.GetLicensePath())
Expand Down Expand Up @@ -93,10 +105,13 @@ func TestPreflights(t *testing.T) {
assert: func(t *testing.T, results *preflights.Output) {
expected := map[string]bool{
// TODO: work to remove these
"System Clock": true,
"'devices' Cgroup Controller": true,
"API Access": true,
"Proxy Registry Access": true,
"System Clock": true,
"'devices' Cgroup Controller": true,
"API Access": true,
"Proxy Registry Access": true,
"Kubelet Port Availability": true,
"Calico Communication Port Availability": true,
"Local Artifact Mirror Port Availability": true,
// as long as fio ran successfully, we're good
"Filesystem Write Latency": true,
}
Expand Down Expand Up @@ -124,6 +139,26 @@ func TestPreflights(t *testing.T) {
}
},
},
{
name: "Should contain port failures",
assert: func(t *testing.T, results *preflights.Output) {
expected := map[string]bool{
"Kubelet Port Availability": false,
"Calico Communication Port Availability": false,
"Local Artifact Mirror Port Availability": false,
}
for _, res := range results.Fail {
if _, ok := expected[res.Title]; ok {
expected[res.Title] = true
}
}
for title, found := range expected {
if !found {
t.Errorf("expected port failure not found: %q", title)
}
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
13 changes: 11 additions & 2 deletions e2e/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func TestSingleNodeDisasterRecovery(t *testing.T) {
t.Fatalf("fail to reset the installation: %v", err)
}

t.Logf("%s: waiting for nodes to reboot", time.Now().Format(time.RFC3339))
time.Sleep(30 * time.Second)

t.Logf("%s: restoring the installation", time.Now().Format(time.RFC3339))
line = append([]string{"restore-installation.exp"}, testArgs...)
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
Expand Down Expand Up @@ -156,6 +159,9 @@ func TestSingleNodeDisasterRecoveryWithProxy(t *testing.T) {
t.Fatalf("fail to reset the installation: %v", err)
}

t.Logf("%s: waiting for nodes to reboot", time.Now().Format(time.RFC3339))
time.Sleep(30 * time.Second)

t.Logf("%s: restoring the installation", time.Now().Format(time.RFC3339))
line = append([]string{"restore-installation.exp"}, testArgs...)
line = append(line, "--http-proxy", cluster.HTTPProxy)
Expand Down Expand Up @@ -229,6 +235,9 @@ func TestSingleNodeResumeDisasterRecovery(t *testing.T) {
t.Fatalf("fail to reset the installation: %v", err)
}

t.Logf("%s: waiting for nodes to reboot", time.Now().Format(time.RFC3339))
time.Sleep(30 * time.Second)

t.Logf("%s: restoring the installation", time.Now().Format(time.RFC3339))
line = append([]string{"resume-restore.exp"}, testArgs...)
if _, _, err := RunCommandOnNode(t, tc, 0, line); err != nil {
Expand Down Expand Up @@ -463,7 +472,7 @@ func TestMultiNodeHADisasterRecovery(t *testing.T) {
}

// reset the cluster
line = []string{"reset-installation.sh", "--force", "--reboot"}
line = []string{"reset-installation.sh", "--force"}
t.Logf("%s: resetting the installation on node 2", time.Now().Format(time.RFC3339))
if _, _, err := RunCommandOnNode(t, tc, 2, line); err != nil {
t.Fatalf("fail to reset the installation: %v", err)
Expand Down Expand Up @@ -681,7 +690,7 @@ func TestMultiNodeAirgapHADisasterRecovery(t *testing.T) {
}

// reset the cluster
line = []string{"reset-installation.sh", "--force", "--reboot"}
line = []string{"reset-installation.sh", "--force"}
t.Logf("%s: resetting the installation on node 2", time.Now().Format(time.RFC3339))
if _, _, err := RunCommandOnNode(t, tc, 2, line); err != nil {
t.Fatalf("fail to reset the installation: %v", err)
Expand Down
Loading
Loading