Skip to content

Commit c75303c

Browse files
committed
fix: change the offline client from seed peer to peer
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
1 parent 9d252a5 commit c75303c

File tree

9 files changed

+159
-7
lines changed

9 files changed

+159
-7
lines changed

.github/workflows/e2e-v2-nydus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
KIND_VERSION: v0.12.0
1919
CONTAINERD_VERSION: v1.5.2
2020
NERDCTL_VER: 0.22.2
21-
KIND_CONFIG_PATH: test/testdata/kind/config-v2.yaml
21+
KIND_CONFIG_PATH: test/testdata/kind/config-v2-nydus.yaml
2222
DRAGONFLY_CHARTS_PATH: deploy/helm-charts/charts/dragonfly
2323
NYDUS_SNAPSHOTTER_CHARTS_PATH: deploy/helm-charts/charts/nydus-snapshotter
2424

.github/workflows/e2e-v2.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ jobs:
120120
kind load docker-image dragonflyoss/client:latest
121121
kind load docker-image dragonflyoss/dfinit:latest
122122
123+
- name: Remove and add taints to node
124+
run: |
125+
kubectl taint nodes kind-control-plane node-role.kubernetes.io/master:NoSchedule-
126+
kubectl taint nodes kind-worker role=worker:NoSchedule
127+
123128
- name: Setup dragonfly
124129
run: |
125130
helm install --wait --timeout 15m --dependency-update --create-namespace --namespace dragonfly-system -f ${{ matrix.charts-config }} dragonfly ${{ env.DRAGONFLY_CHARTS_PATH }}

scheduler/service/service_v2_test.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,115 @@ func TestServiceV2_AnnounceHost(t *testing.T) {
882882
}
883883
}
884884

885+
func TestServiceV2_ListHosts(t *testing.T) {
886+
tests := []struct {
887+
name string
888+
mock func(host []*resource.Host, hostManager resource.HostManager, mr *resource.MockResourceMockRecorder, mh *resource.MockHostManagerMockRecorder)
889+
expect func(t *testing.T, host *resource.Host, resp []*commonv2.Host, err error)
890+
}{
891+
{
892+
name: "host loaded successfully",
893+
mock: func(host []*resource.Host, hostManager resource.HostManager, mr *resource.MockResourceMockRecorder, mh *resource.MockHostManagerMockRecorder) {
894+
gomock.InOrder(
895+
mr.HostManager().Return(hostManager).Times(1),
896+
mh.LoadAll().Return(host).Times(1),
897+
)
898+
},
899+
expect: func(t *testing.T, host *resource.Host, resp []*commonv2.Host, err error) {
900+
assert := assert.New(t)
901+
assert.NoError(err)
902+
assert.Equal(len(resp), 1)
903+
assert.EqualValues(resp[0], &commonv2.Host{
904+
Id: mockHostID,
905+
Type: uint32(pkgtypes.HostTypeNormal),
906+
Hostname: "foo",
907+
Ip: "127.0.0.1",
908+
Port: 8003,
909+
DownloadPort: mockRawHost.DownloadPort,
910+
Cpu: &commonv2.CPU{
911+
LogicalCount: mockCPU.LogicalCount,
912+
PhysicalCount: mockCPU.PhysicalCount,
913+
Percent: mockCPU.Percent,
914+
ProcessPercent: mockCPU.ProcessPercent,
915+
Times: &commonv2.CPUTimes{
916+
User: mockCPU.Times.User,
917+
System: mockCPU.Times.System,
918+
Idle: mockCPU.Times.Idle,
919+
Nice: mockCPU.Times.Nice,
920+
Iowait: mockCPU.Times.Iowait,
921+
Irq: mockCPU.Times.Irq,
922+
Softirq: mockCPU.Times.Softirq,
923+
Steal: mockCPU.Times.Steal,
924+
Guest: mockCPU.Times.Guest,
925+
GuestNice: mockCPU.Times.GuestNice,
926+
},
927+
},
928+
Memory: &commonv2.Memory{
929+
Total: mockMemory.Total,
930+
Available: mockMemory.Available,
931+
Used: mockMemory.Used,
932+
UsedPercent: mockMemory.UsedPercent,
933+
ProcessUsedPercent: mockMemory.ProcessUsedPercent,
934+
Free: mockMemory.Free,
935+
},
936+
Network: &commonv2.Network{
937+
TcpConnectionCount: mockNetwork.TCPConnectionCount,
938+
UploadTcpConnectionCount: mockNetwork.UploadTCPConnectionCount,
939+
Location: &mockNetwork.Location,
940+
Idc: &mockNetwork.IDC,
941+
DownloadRate: mockNetwork.DownloadRate,
942+
DownloadRateLimit: mockNetwork.DownloadRateLimit,
943+
UploadRate: mockNetwork.UploadRate,
944+
UploadRateLimit: mockNetwork.UploadRateLimit,
945+
},
946+
Disk: &commonv2.Disk{
947+
Total: mockDisk.Total,
948+
Free: mockDisk.Free,
949+
Used: mockDisk.Used,
950+
UsedPercent: mockDisk.UsedPercent,
951+
InodesTotal: mockDisk.InodesTotal,
952+
InodesUsed: mockDisk.InodesUsed,
953+
InodesFree: mockDisk.InodesFree,
954+
InodesUsedPercent: mockDisk.InodesUsedPercent,
955+
},
956+
Build: &commonv2.Build{
957+
GitVersion: mockBuild.GitVersion,
958+
GitCommit: &mockBuild.GitCommit,
959+
GoVersion: &mockBuild.GoVersion,
960+
Platform: &mockBuild.Platform,
961+
},
962+
})
963+
},
964+
},
965+
}
966+
967+
for _, tc := range tests {
968+
t.Run(tc.name, func(t *testing.T) {
969+
ctl := gomock.NewController(t)
970+
defer ctl.Finish()
971+
scheduling := schedulingmocks.NewMockScheduling(ctl)
972+
res := resource.NewMockResource(ctl)
973+
dynconfig := configmocks.NewMockDynconfigInterface(ctl)
974+
storage := storagemocks.NewMockStorage(ctl)
975+
hostManager := resource.NewMockHostManager(ctl)
976+
host := resource.NewHost(
977+
mockRawHost.ID, mockRawHost.IP, mockRawHost.Hostname,
978+
mockRawHost.Port, mockRawHost.DownloadPort, mockRawHost.Type)
979+
host.CPU = mockCPU
980+
host.Memory = mockMemory
981+
host.Network = mockNetwork
982+
host.Disk = mockDisk
983+
host.Build = mockBuild
984+
hosts := []*resource.Host{host}
985+
svc := NewV2(&config.Config{Scheduler: mockSchedulerConfig, Metrics: config.MetricsConfig{EnableHost: true}}, res, scheduling, dynconfig, storage)
986+
987+
tc.mock(hosts, hostManager, res.EXPECT(), hostManager.EXPECT())
988+
resp, err := svc.ListHosts(context.Background())
989+
tc.expect(t, host, resp.Hosts, err)
990+
})
991+
}
992+
}
993+
885994
func TestServiceV2_DeleteHost(t *testing.T) {
886995
tests := []struct {
887996
name string

test/e2e/v2/leave_host_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ var _ = Describe("Clients go offline normally and abnormally", func() {
5858
hostCount := util.Servers[util.SeedClientServerName].Replicas + util.Servers[util.ClientServerName].Replicas
5959
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount))
6060

61-
podName, err := util.GetClientPodName()
61+
podName, err := util.GetClientPodName(1)
6262
Expect(err).NotTo(HaveOccurred())
6363

6464
out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName).CombinedOutput()
6565
fmt.Println(string(out))
6666
Expect(err).NotTo(HaveOccurred())
6767
Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount))
6868

69-
podName, err = util.GetClientPodName()
69+
podName, err = util.GetClientPodName(1)
7070
Expect(err).NotTo(HaveOccurred())
7171

7272
out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--force", "--grace-period=0").CombinedOutput()

test/e2e/v2/util/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ var Servers = map[string]server{
5757
Name: ClientServerName,
5858
Namespace: DragonflyNamespace,
5959
LogDirName: "dfdaemon",
60-
Replicas: 1,
60+
Replicas: 2,
6161
},
6262
}

test/e2e/v2/util/exec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func KubeCtlCopyCommand(ns, pod, source, target string) *exec.Cmd {
103103
}
104104

105105
func ClientExec() (*PodExec, error) {
106-
podName, err := GetClientPodName()
106+
podName, err := GetClientPodName(0)
107107
if err != nil {
108108
return nil, err
109109
}
@@ -126,9 +126,9 @@ func ManagerExec(n int) (*PodExec, error) {
126126
return NewPodExec(DragonflyNamespace, podName, "manager"), nil
127127
}
128128

129-
func GetClientPodName() (string, error) {
129+
func GetClientPodName(n int) (string, error) {
130130
out, err := KubeCtlCommand("-n", DragonflyNamespace, "get", "pod", "-l", "component=client",
131-
"-o", fmt.Sprintf("jsonpath='{range .items[0]}{.metadata.name}{end}'")).CombinedOutput()
131+
"-o", fmt.Sprintf("jsonpath='{range .items[%d]}{.metadata.name}{end}'", n)).CombinedOutput()
132132
if err != nil {
133133
return "", err
134134
}

test/testdata/charts/config-v2.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ client:
114114
limits:
115115
cpu: "2"
116116
memory: "4Gi"
117+
tolerations:
118+
- key: "role"
119+
operator: "Equal"
120+
value: "worker"
121+
effect: "NoSchedule"
117122
extraVolumeMounts:
118123
- name: logs
119124
mountPath: "/var/log/"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
networking:
4+
ipFamily: dual
5+
nodes:
6+
- role: control-plane
7+
image: kindest/node:v1.23.4
8+
extraPortMappings:
9+
- containerPort: 4001
10+
hostPort: 4001
11+
protocol: TCP
12+
- containerPort: 4003
13+
hostPort: 4003
14+
protocol: TCP
15+
- containerPort: 30802
16+
hostPort: 8002
17+
protocol: TCP
18+
extraMounts:
19+
- hostPath: ./test/testdata/containerd/config-v2.toml
20+
containerPath: /etc/containerd/config.toml
21+
- hostPath: /tmp/artifact
22+
containerPath: /tmp/artifact
23+
- hostPath: /dev/fuse
24+
containerPath: /dev/fuse

test/testdata/kind/config-v2.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ nodes:
2222
containerPath: /tmp/artifact
2323
- hostPath: /dev/fuse
2424
containerPath: /dev/fuse
25+
- role: worker
26+
image: kindest/node:v1.23.4
27+
extraMounts:
28+
- hostPath: ./test/testdata/containerd/config-v2.toml
29+
containerPath: /etc/containerd/config.toml
30+
- hostPath: /tmp/artifact
31+
containerPath: /tmp/artifact
32+
- hostPath: /dev/fuse
33+
containerPath: /dev/fuse

0 commit comments

Comments
 (0)