Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Cardoso <[email protected]>
  • Loading branch information
osodracnai committed Nov 17, 2023
1 parent 4e7a4b1 commit dbf1d0e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
35 changes: 20 additions & 15 deletions contrib/util/k3s-killall.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/sh
[ $(id -u) -eq 0 ] || exec sudo $0 $@


for bin in /var/lib/rancher/k3s/data/**/bin/; do
[ -d $bin ] && export PATH=$PATH:$bin:$bin/aux
[ -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)
[ -s "$service" ] && systemctl stop "$(basename "$service")"
done

for service in /etc/init.d/k3s*; do
[ -x $service ] && $service stop
[ -x "$service" ] && $service stop
done

pschildren() {
Expand All @@ -23,27 +23,30 @@ pschildren() {
}

pstree() {
for pid in $@; do
echo $pid
for child in $(pschildren $pid); do
pstree $child

for pid in "$@"; do
if [ -n "$$" ]; then
echo "$pid"
for child in $(pschildren "$pid"); do
pstree "$child"
done
fi
done
}

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

remove_interfaces() {
# Delete network interface(s) that match 'master cni0'
ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do
iface=${iface%%@*}
[ -z "$iface" ] || ip link delete $iface
[ -z "$iface" ] || ip link delete "$iface"
done

# Delete cni related interfaces
Expand All @@ -64,7 +67,7 @@ getshims() {
ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1
}

killtree $({ set +x; } 2>/dev/null; getshims; set -x)


do_unmount_and_remove() {
set +x
Expand All @@ -74,6 +77,8 @@ do_unmount_and_remove() {
set -x
}

killtree "$({ set +x; } 2>/dev/null; getshims; set -x)"

do_unmount_and_remove '/run/k3s'
do_unmount_and_remove '/var/lib/rancher/k3s'
do_unmount_and_remove '/var/lib/kubelet/pods'
Expand All @@ -87,4 +92,4 @@ remove_interfaces

rm -rf /var/lib/cni/
iptables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | iptables-restore
ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | ip6tables-restore
ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | ip6tables-restore
6 changes: 6 additions & 0 deletions tests/e2e/killall/killall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ var _ = Describe("Verify Create", Ordered, func() {
Expect(err).ToNot(HaveOccurred())
}
fmt.Println(out)
process, err := e2e.RunCmdOnNode("ps aux | grep k3s", serverNodeNames[0])
if err != nil {
fmt.Println(err.Error())
Expect(err).ToNot(HaveOccurred())
}
fmt.Println(process)
})
})

Expand Down
26 changes: 26 additions & 0 deletions tests/integration/startup/startup_int_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package integration

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"

Expand Down Expand Up @@ -124,6 +126,7 @@ var _ = Describe("startup tests", Ordered, func() {
Expect(err).ToNot(HaveOccurred())
Expect(apiInfo).To(ContainSubstring("11.11.22.22"))
})

It("dies cleanly", func() {
Expect(testutil.K3sKillServer(startupServer)).To(Succeed())
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
Expand Down Expand Up @@ -263,6 +266,29 @@ var _ = Describe("startup tests", Ordered, func() {
Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
})
})
FWhen("a server with a dummy pod", func() {
It("is created with no arguments", func() {
var err error
startupServer, err = testutil.K3sStartServer(startupServerArgs...)
Expect(err).ToNot(HaveOccurred())
})
It("has the default pods deployed", func() {
Eventually(func() error {
return testutil.K3sDefaultDeployments()
}, "120s", "5s").Should(Succeed())
})
It("dies cleanly", func() {
res, err := testutil.K3sCmd("k3s-killall")
Expect(err).ToNot(HaveOccurred())
fmt.Print(res)
cmd := exec.Command("ps aux", "|", "grep k3s")
out, err := cmd.Output()
Expect(err).ToNot(HaveOccurred())
fmt.Print(string(out))
//Expect(testutil.K3sKillServer(startupServer)).To(Succeed())
//Expect(testutil.K3sCleanup(-1, "")).To(Succeed())
})
})

})

Expand Down

0 comments on commit dbf1d0e

Please sign in to comment.