Skip to content

Commit

Permalink
Fix internal killall, use start E2E, not a new test
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Feb 5, 2024
1 parent dbf1d0e commit 825f0b0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 218 deletions.
2 changes: 1 addition & 1 deletion cmd/k3s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
cmds.NewCRICTL(externalCLIAction("crictl", dataDir)),
cmds.NewCtrCommand(externalCLIAction("ctr", dataDir)),
cmds.NewCheckConfigCommand(externalCLIAction("check-config", dataDir)),
cmds.NewKillAllCommand(externalCLIAction("test", dataDir)),
cmds.NewKillAllCommand(externalCLIAction("k3s-killall", dataDir)),
cmds.NewTokenCommands(
tokenCommand,
tokenCommand,
Expand Down
19 changes: 9 additions & 10 deletions contrib/util/k3s-killall.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
#!/usr/bin/env sh


for bin in /var/lib/rancher/k3s/data/**/bin/; do
[ -d "$bin" ] && export PATH=$PATH:$bin:$bin/aux
done


set -x

for service in /etc/systemd/system/k3s*.service; do
[ -s "$service" ] && systemctl stop "$(basename "$service")"
Expand All @@ -25,21 +25,22 @@ pschildren() {
pstree() {

for pid in "$@"; do
if [ -n "$$" ]; then
echo "$pid"
# Don't return the current process
if [ "$pid" != "$$" ]; then
echo "$pid"
fi
for child in $(pschildren "$pid"); do
pstree "$child"
done
fi
done
}

killtree() {
kill -9 "$(
kill -9 $(
{ set +x; } 2>/dev/null;
pstree "$@";
set -x;
)" 2>/dev/null
) 2>/dev/null
}

remove_interfaces() {
Expand Down Expand Up @@ -67,13 +68,11 @@ getshims() {
ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1
}



do_unmount_and_remove() {
set +x
while read -r _ path _; do
case "$path" in $1*) echo "$path" ;; esac
done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount "$0" && rm -rf "$0"'
done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount -f "$0" && rm -rf "$0"'
set -x
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmds/killall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "github.com/urfave/cli"

func NewKillAllCommand(action func(*cli.Context) error) cli.Command {
return cli.Command{
Name: "k3s-killall",
Usage: "Run k3s-killall.sh script",
Name: "killall",
Usage: "Kill all K3s and associated child processes",
SkipFlagParsing: true,
SkipArgReorder: true,
Action: action,
Expand Down
2 changes: 1 addition & 1 deletion scripts/package-cli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for i in bandwidth bridge firewall flannel host-local loopback portmap; do
done

cp contrib/util/check-config.sh bin/check-config
cp contrib/util/k3s-killall.sh bin/test
cp contrib/util/k3s-killall.sh bin/k3s-killall

rm -rf build/data
mkdir -p build/data build/out
Expand Down
82 changes: 0 additions & 82 deletions tests/e2e/killall/Vagrantfile

This file was deleted.

115 changes: 0 additions & 115 deletions tests/e2e/killall/killall_test.go

This file was deleted.

63 changes: 56 additions & 7 deletions tests/e2e/startup/startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ var _ = Describe("Various Startup Configurations", Ordered, func() {
_, _ = e2e.ParsePods(kubeConfigFile, true)
})
It("Kills the cluster", func() {
err := KillK3sCluster(append(serverNodeNames, agentNodeNames...))
Expect(err).NotTo(HaveOccurred())
Expect(KillK3sCluster(append(serverNodeNames, agentNodeNames...))).To(Succeed())
})
})
Context("Verify prefer-bundled-bin flag", func() {
Expand Down Expand Up @@ -177,8 +176,7 @@ var _ = Describe("Various Startup Configurations", Ordered, func() {
_, _ = e2e.ParsePods(kubeConfigFile, true)
})
It("Kills the cluster", func() {
err := KillK3sCluster(append(serverNodeNames, agentNodeNames...))
Expect(err).NotTo(HaveOccurred())
Expect(KillK3sCluster(append(serverNodeNames, agentNodeNames...))).To(Succeed())
})
})
Context("Verify disable-agent and egress-selector-mode flags", func() {
Expand Down Expand Up @@ -248,8 +246,7 @@ var _ = Describe("Various Startup Configurations", Ordered, func() {
})

It("Kills the cluster", func() {
err := KillK3sCluster(append(serverNodeNames, agentNodeNames...))
Expect(err).NotTo(HaveOccurred())
Expect(KillK3sCluster(append(serverNodeNames, agentNodeNames...))).To(Succeed())
})
})
Context("Verify server fails to start with bootstrap token", func() {
Expand All @@ -265,9 +262,61 @@ var _ = Describe("Various Startup Configurations", Ordered, func() {

})
It("Kills the cluster", func() {
err := KillK3sCluster(append(serverNodeNames, agentNodeNames...))
Expect(KillK3sCluster(append(serverNodeNames, agentNodeNames...))).To(Succeed())
})
})
Context("Verify k3s killall subcommand works on all nodes", func() {
It("Starts K3s with no issues", func() {
err := StartK3sCluster(append(serverNodeNames, agentNodeNames...), "", "")
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))

fmt.Println("CLUSTER CONFIG")
fmt.Println("OS:", *nodeOS)
fmt.Println("Server Nodes:", serverNodeNames)
fmt.Println("Agent Nodes:", agentNodeNames)
kubeConfigFile, err = e2e.GenKubeConfigFile(serverNodeNames[0])
Expect(err).NotTo(HaveOccurred())
})

It("Checks node and pod status", func() {
fmt.Printf("\nFetching node status\n")
Eventually(func(g Gomega) {
nodes, err := e2e.ParseNodes(kubeConfigFile, false)
g.Expect(err).NotTo(HaveOccurred())
for _, node := range nodes {
g.Expect(node.Status).Should(Equal("Ready"))
}
}, "360s", "5s").Should(Succeed())
_, _ = e2e.ParseNodes(kubeConfigFile, true)

fmt.Printf("\nFetching pods status\n")
Eventually(func(g Gomega) {
pods, err := e2e.ParsePods(kubeConfigFile, false)
g.Expect(err).NotTo(HaveOccurred())
for _, pod := range pods {
if strings.Contains(pod.Name, "helm-install") {
g.Expect(pod.Status).Should(Equal("Completed"), pod.Name)
} else {
g.Expect(pod.Status).Should(Equal("Running"), pod.Name)
}
}
}, "360s", "5s").Should(Succeed())
_, _ = e2e.ParsePods(kubeConfigFile, true)
})

It("Kills the cluster", func() {
for _, node := range append(serverNodeNames, agentNodeNames...) {
_, err := e2e.RunCmdOnNode("k3s killall", node)
Expect(err).NotTo(HaveOccurred())
}
})
It("Checks that no k3s processes are running", func() {
Eventually(func(g Gomega) {
for _, node := range append(serverNodeNames, agentNodeNames...) {
g.Expect(e2e.RunCmdOnNode("ps x | grep k3s || true", node)).To(BeEmpty())
}
}, "20s", "5s").Should(Succeed())
})
})
})

Expand Down

0 comments on commit 825f0b0

Please sign in to comment.