Skip to content

Commit 927e11d

Browse files
committed
fix: taint master node in leave host test
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
1 parent 8704cd0 commit 927e11d

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

scheduler/service/service_v2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ func (v *V2) DeleteHost(ctx context.Context, req *schedulerv2.DeleteHostRequest)
789789

790790
// Leave peers in host.
791791
host.LeavePeers()
792+
v.resource.HostManager().Delete(req.GetHostId())
792793
return nil
793794
}
794795

scheduler/service/service_v2_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ func TestServiceV2_DeleteHost(t *testing.T) {
10111011
gomock.InOrder(
10121012
mr.HostManager().Return(hostManager).Times(1),
10131013
mh.Load(gomock.Any()).Return(host, true).Times(1),
1014+
mr.HostManager().Return(hostManager).Times(1),
1015+
mh.Delete(gomock.Any()).Times(1),
10141016
)
10151017
},
10161018
expect: func(t *testing.T, peer *resource.Peer, err error) {
@@ -1026,6 +1028,8 @@ func TestServiceV2_DeleteHost(t *testing.T) {
10261028
gomock.InOrder(
10271029
mr.HostManager().Return(hostManager).Times(1),
10281030
mh.Load(gomock.Any()).Return(host, true).Times(1),
1031+
mr.HostManager().Return(hostManager).Times(1),
1032+
mh.Delete(gomock.Any()).Times(1),
10291033
)
10301034
},
10311035
expect: func(t *testing.T, peer *resource.Peer, err error) {

test/e2e/v2/leave_host_test.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,76 @@ import (
3434
var _ = Describe("Clients Leaving", func() {
3535
Context("normally", func() {
3636
It("number of hosts should be ok", Label("host", "leave"), func() {
37+
// create scheduler GRPC client
3738
grpcCredentials := insecure.NewCredentials()
3839
schedulerClient, err := schedulerclient.GetV2ByAddr(context.Background(), ":8002", grpc.WithTransportCredentials(grpcCredentials))
3940
Expect(err).NotTo(HaveOccurred())
4041

42+
// get host count
4143
hostCount := util.Servers[util.SeedClientServerName].Replicas + util.Servers[util.ClientServerName].Replicas
4244
time.Sleep(10 * time.Minute)
4345
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount))
4446

47+
// get client pod name in master node
4548
podName, err := util.GetClientPodNameInMaster()
4649
Expect(err).NotTo(HaveOccurred())
4750

48-
out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName).CombinedOutput()
51+
// taint master node
52+
out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule").CombinedOutput()
53+
fmt.Println(string(out))
54+
Expect(err).NotTo(HaveOccurred())
55+
56+
// delete client pod in master, client will leave normally
57+
out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--grace-period=30").CombinedOutput()
4958
fmt.Println(string(out))
5059
Expect(err).NotTo(HaveOccurred())
5160

5261
// wait fot the client to leave gracefully
53-
time.Sleep(1 * time.Minute)
54-
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount))
62+
time.Sleep(30 * time.Second)
63+
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount - 1))
64+
65+
// remove taint in master node
66+
out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule-").CombinedOutput()
67+
fmt.Println(string(out))
68+
Expect(err).NotTo(HaveOccurred())
5569
})
5670
})
5771

5872
Context("abnormally", func() {
5973
It("number of hosts should be ok", Label("host", "leave"), func() {
74+
// create scheduler GRPC client
6075
grpcCredentials := insecure.NewCredentials()
6176
schedulerClient, err := schedulerclient.GetV2ByAddr(context.Background(), ":8002", grpc.WithTransportCredentials(grpcCredentials))
6277
Expect(err).NotTo(HaveOccurred())
6378

79+
// get host count
6480
hostCount := util.Servers[util.SeedClientServerName].Replicas + util.Servers[util.ClientServerName].Replicas
81+
time.Sleep(30 * time.Second)
6582
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount))
6683

84+
// get client pod name in master node
6785
podName, err := util.GetClientPodNameInMaster()
6886
Expect(err).NotTo(HaveOccurred())
6987

70-
out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--force", "--grace-period=0").CombinedOutput()
88+
// taint master node
89+
out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule").CombinedOutput()
90+
fmt.Println(string(out))
91+
Expect(err).NotTo(HaveOccurred())
92+
93+
// force delete client pod in master, client will leave abnormally
94+
out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--force", "--grace-period=0").CombinedOutput()
7195
fmt.Println(string(out))
7296
Expect(err).NotTo(HaveOccurred())
7397

7498
// wait for host gc
75-
time.Sleep(6 * time.Minute)
76-
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount))
99+
time.Sleep(2 * time.Minute)
100+
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount - 1))
101+
102+
// remove taint in master node
103+
out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "taint", "nodes", "kind-control-plane", "master:NoSchedule-").CombinedOutput()
104+
fmt.Println(string(out))
105+
Expect(err).NotTo(HaveOccurred())
106+
time.Sleep(30 * time.Second)
77107
})
78108
})
79109
})

test/testdata/charts/config-v2.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ scheduler:
6262
enableHost: true
6363
config:
6464
verbose: true
65+
scheduler:
66+
gc:
67+
hostGCInterval: 2m
6568

6669
seedClient:
6770
enable: true

0 commit comments

Comments
 (0)