From dd556dec4e1e676e829853f701577638a086f205 Mon Sep 17 00:00:00 2001 From: BruceAko Date: Wed, 16 Oct 2024 00:29:32 +0800 Subject: [PATCH] fix: taint master node in leave host test Signed-off-by: BruceAko --- test/e2e/v2/leave_host_test.go | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/e2e/v2/leave_host_test.go b/test/e2e/v2/leave_host_test.go index 31ada58ca24..d4e398f9b16 100644 --- a/test/e2e/v2/leave_host_test.go +++ b/test/e2e/v2/leave_host_test.go @@ -34,46 +34,70 @@ import ( var _ = Describe("Clients Leaving", func() { Context("normally", func() { It("number of hosts should be ok", Label("host", "leave"), func() { + // create scheduler GRPC client grpcCredentials := insecure.NewCredentials() schedulerClient, err := schedulerclient.GetV2ByAddr(context.Background(), ":8002", grpc.WithTransportCredentials(grpcCredentials)) Expect(err).NotTo(HaveOccurred()) + // get host count hostCount := util.Servers[util.SeedClientServerName].Replicas + util.Servers[util.ClientServerName].Replicas time.Sleep(10 * time.Minute) Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount)) + // get client pod name in master node podName, err := util.GetClientPodNameInMaster() Expect(err).NotTo(HaveOccurred()) - out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName).CombinedOutput() + // taint master node + out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule").CombinedOutput() + fmt.Println(string(out)) + Expect(err).NotTo(HaveOccurred()) + + // delete client pod in master, client will leave normally + out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName).CombinedOutput() fmt.Println(string(out)) Expect(err).NotTo(HaveOccurred()) // wait fot the client to leave gracefully time.Sleep(1 * time.Minute) - Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount)) + Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount - 1)) + + // remove taint in master node + out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule-").CombinedOutput() + fmt.Println(string(out)) + Expect(err).NotTo(HaveOccurred()) }) }) Context("abnormally", func() { It("number of hosts should be ok", Label("host", "leave"), func() { + // create scheduler GRPC client grpcCredentials := insecure.NewCredentials() schedulerClient, err := schedulerclient.GetV2ByAddr(context.Background(), ":8002", grpc.WithTransportCredentials(grpcCredentials)) Expect(err).NotTo(HaveOccurred()) + // get host count hostCount := util.Servers[util.SeedClientServerName].Replicas + util.Servers[util.ClientServerName].Replicas + time.Sleep(1 * time.Minute) Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount)) + // get client pod name in master node podName, err := util.GetClientPodNameInMaster() Expect(err).NotTo(HaveOccurred()) - out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--force", "--grace-period=0").CombinedOutput() + // taint master node + out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule").CombinedOutput() + fmt.Println(string(out)) + Expect(err).NotTo(HaveOccurred()) + + // force delete client pod in master, client will leave abnormally + out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--force", "--grace-period=0").CombinedOutput() fmt.Println(string(out)) Expect(err).NotTo(HaveOccurred()) // wait for host gc - time.Sleep(6 * time.Minute) - Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount)) + time.Sleep(5 * time.Minute) + Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount - 1)) }) }) })