From 18a5fddf76a70cab0f9cdd0ec9fbee311b1b6f5d Mon Sep 17 00:00:00 2001 From: BruceAko Date: Mon, 30 Sep 2024 16:32:43 +0800 Subject: [PATCH] fix: change the offline client from seed peer to peer Signed-off-by: BruceAko --- .github/workflows/e2e-v2-nydus.yml | 2 +- .github/workflows/e2e-v2.yml | 5 ++ scheduler/service/service_v2_test.go | 110 ++++++++++++++++++++++++ test/e2e/v2/leave_host_test.go | 4 +- test/e2e/v2/util/constants.go | 2 +- test/e2e/v2/util/exec.go | 6 +- test/testdata/charts/config-v2.yaml | 5 ++ test/testdata/kind/config-v2-nydus.yaml | 24 ++++++ test/testdata/kind/config-v2.yaml | 9 ++ 9 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 test/testdata/kind/config-v2-nydus.yaml diff --git a/.github/workflows/e2e-v2-nydus.yml b/.github/workflows/e2e-v2-nydus.yml index 26fe05764fa..25ae6532ab0 100644 --- a/.github/workflows/e2e-v2-nydus.yml +++ b/.github/workflows/e2e-v2-nydus.yml @@ -18,7 +18,7 @@ env: KIND_VERSION: v0.12.0 CONTAINERD_VERSION: v1.5.2 NERDCTL_VER: 0.22.2 - KIND_CONFIG_PATH: test/testdata/kind/config-v2.yaml + KIND_CONFIG_PATH: test/testdata/kind/config-v2-nydus.yaml DRAGONFLY_CHARTS_PATH: deploy/helm-charts/charts/dragonfly NYDUS_SNAPSHOTTER_CHARTS_PATH: deploy/helm-charts/charts/nydus-snapshotter diff --git a/.github/workflows/e2e-v2.yml b/.github/workflows/e2e-v2.yml index 1b6bca64f86..ebf19215674 100644 --- a/.github/workflows/e2e-v2.yml +++ b/.github/workflows/e2e-v2.yml @@ -120,6 +120,11 @@ jobs: kind load docker-image dragonflyoss/client:latest kind load docker-image dragonflyoss/dfinit:latest + - name: Remove and add taints to node + run: | + kubectl taint nodes kind-control-plane node-role.kubernetes.io/master:NoSchedule- + kubectl taint nodes kind-worker role=worker:NoSchedule + - name: Setup dragonfly run: | helm install --wait --timeout 15m --dependency-update --create-namespace --namespace dragonfly-system -f ${{ matrix.charts-config }} dragonfly ${{ env.DRAGONFLY_CHARTS_PATH }} diff --git a/scheduler/service/service_v2_test.go b/scheduler/service/service_v2_test.go index 5ef3bf32765..2fed43348e8 100644 --- a/scheduler/service/service_v2_test.go +++ b/scheduler/service/service_v2_test.go @@ -882,6 +882,116 @@ func TestServiceV2_AnnounceHost(t *testing.T) { } } +func TestServiceV2_ListHosts(t *testing.T) { + tests := []struct { + name string + mock func(host []*resource.Host, hostManager resource.HostManager, mr *resource.MockResourceMockRecorder, mh *resource.MockHostManagerMockRecorder) + expect func(t *testing.T, host *resource.Host, resp []*commonv2.Host, err error) + }{ + { + name: "host loaded successfully", + mock: func(host []*resource.Host, hostManager resource.HostManager, mr *resource.MockResourceMockRecorder, mh *resource.MockHostManagerMockRecorder) { + gomock.InOrder( + mr.HostManager().Return(hostManager).Times(1), + mh.LoadAll().Return(host).Times(1), + ) + }, + expect: func(t *testing.T, host *resource.Host, resp []*commonv2.Host, err error) { + assert := assert.New(t) + assert.NoError(err) + assert.Equal(len(resp), 1) + assert.EqualValues(resp[0], &commonv2.Host{ + Id: mockHostID, + Type: uint32(pkgtypes.HostTypeNormal), + Hostname: "foo", + Ip: "127.0.0.1", + Port: 8003, + DownloadPort: 8001, + Cpu: &commonv2.CPU{ + LogicalCount: mockCPU.LogicalCount, + PhysicalCount: mockCPU.PhysicalCount, + Percent: mockCPU.Percent, + ProcessPercent: mockCPU.ProcessPercent, + Times: &commonv2.CPUTimes{ + User: mockCPU.Times.User, + System: mockCPU.Times.System, + Idle: mockCPU.Times.Idle, + Nice: mockCPU.Times.Nice, + Iowait: mockCPU.Times.Iowait, + Irq: mockCPU.Times.Irq, + Softirq: mockCPU.Times.Softirq, + Steal: mockCPU.Times.Steal, + Guest: mockCPU.Times.Guest, + GuestNice: mockCPU.Times.GuestNice, + }, + }, + Memory: &commonv2.Memory{ + Total: mockMemory.Total, + Available: mockMemory.Available, + Used: mockMemory.Used, + UsedPercent: mockMemory.UsedPercent, + ProcessUsedPercent: mockMemory.ProcessUsedPercent, + Free: mockMemory.Free, + }, + Network: &commonv2.Network{ + TcpConnectionCount: mockNetwork.TCPConnectionCount, + UploadTcpConnectionCount: mockNetwork.UploadTCPConnectionCount, + Location: &mockNetwork.Location, + Idc: &mockNetwork.IDC, + DownloadRate: mockNetwork.DownloadRate, + DownloadRateLimit: mockNetwork.DownloadRateLimit, + UploadRate: mockNetwork.UploadRate, + UploadRateLimit: mockNetwork.UploadRateLimit, + }, + Disk: &commonv2.Disk{ + Total: mockDisk.Total, + Free: mockDisk.Free, + Used: mockDisk.Used, + UsedPercent: mockDisk.UsedPercent, + InodesTotal: mockDisk.InodesTotal, + InodesUsed: mockDisk.InodesUsed, + InodesFree: mockDisk.InodesFree, + InodesUsedPercent: mockDisk.InodesUsedPercent, + }, + Build: &commonv2.Build{ + GitVersion: mockBuild.GitVersion, + GitCommit: &mockBuild.GitCommit, + GoVersion: &mockBuild.GoVersion, + Platform: &mockBuild.Platform, + }, + }) + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + ctl := gomock.NewController(t) + defer ctl.Finish() + scheduling := schedulingmocks.NewMockScheduling(ctl) + res := resource.NewMockResource(ctl) + dynconfig := configmocks.NewMockDynconfigInterface(ctl) + storage := storagemocks.NewMockStorage(ctl) + hostManager := resource.NewMockHostManager(ctl) + host := resource.NewHost( + mockRawHost.ID, mockRawHost.IP, mockRawHost.Hostname, + mockRawHost.Port, mockRawHost.DownloadPort, mockRawHost.Type) + host.CPU = mockCPU + host.Memory = mockMemory + host.Network = mockNetwork + host.Disk = mockDisk + host.Build = mockBuild + host.DownloadPort = mockRawHost.DownloadPort + hosts := []*resource.Host{host} + svc := NewV2(&config.Config{Scheduler: mockSchedulerConfig, Metrics: config.MetricsConfig{EnableHost: true}}, res, scheduling, dynconfig, storage) + + tc.mock(hosts, hostManager, res.EXPECT(), hostManager.EXPECT()) + resp, err := svc.ListHosts(context.Background()) + tc.expect(t, host, resp.Hosts, err) + }) + } +} + func TestServiceV2_DeleteHost(t *testing.T) { tests := []struct { name string diff --git a/test/e2e/v2/leave_host_test.go b/test/e2e/v2/leave_host_test.go index 856efbb0228..5e34ddcf3d7 100644 --- a/test/e2e/v2/leave_host_test.go +++ b/test/e2e/v2/leave_host_test.go @@ -58,7 +58,7 @@ var _ = Describe("Clients go offline normally and abnormally", func() { hostCount := util.Servers[util.SeedClientServerName].Replicas + util.Servers[util.ClientServerName].Replicas Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount)) - podName, err := util.GetClientPodName() + podName, err := util.GetClientPodName(1) Expect(err).NotTo(HaveOccurred()) out, err := util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName).CombinedOutput() @@ -66,7 +66,7 @@ var _ = Describe("Clients go offline normally and abnormally", func() { Expect(err).NotTo(HaveOccurred()) Expect(getHostCountFromScheduler(schedulerClient)).To(Equal(hostCount)) - podName, err = util.GetClientPodName() + podName, err = util.GetClientPodName(1) Expect(err).NotTo(HaveOccurred()) out, err = util.KubeCtlCommand("-n", util.DragonflyNamespace, "delete", "pod", podName, "--force", "--grace-period=0").CombinedOutput() diff --git a/test/e2e/v2/util/constants.go b/test/e2e/v2/util/constants.go index 1e220300c36..30f6e6f2344 100644 --- a/test/e2e/v2/util/constants.go +++ b/test/e2e/v2/util/constants.go @@ -57,6 +57,6 @@ var Servers = map[string]server{ Name: ClientServerName, Namespace: DragonflyNamespace, LogDirName: "dfdaemon", - Replicas: 1, + Replicas: 2, }, } diff --git a/test/e2e/v2/util/exec.go b/test/e2e/v2/util/exec.go index 0a9e1819571..b465bdf7a61 100644 --- a/test/e2e/v2/util/exec.go +++ b/test/e2e/v2/util/exec.go @@ -103,7 +103,7 @@ func KubeCtlCopyCommand(ns, pod, source, target string) *exec.Cmd { } func ClientExec() (*PodExec, error) { - podName, err := GetClientPodName() + podName, err := GetClientPodName(0) if err != nil { return nil, err } @@ -126,9 +126,9 @@ func ManagerExec(n int) (*PodExec, error) { return NewPodExec(DragonflyNamespace, podName, "manager"), nil } -func GetClientPodName() (string, error) { +func GetClientPodName(n int) (string, error) { out, err := KubeCtlCommand("-n", DragonflyNamespace, "get", "pod", "-l", "component=client", - "-o", fmt.Sprintf("jsonpath='{range .items[0]}{.metadata.name}{end}'")).CombinedOutput() + "-o", fmt.Sprintf("jsonpath='{range .items[%d]}{.metadata.name}{end}'", n)).CombinedOutput() if err != nil { return "", err } diff --git a/test/testdata/charts/config-v2.yaml b/test/testdata/charts/config-v2.yaml index cb45f1f300d..64cffd06830 100644 --- a/test/testdata/charts/config-v2.yaml +++ b/test/testdata/charts/config-v2.yaml @@ -114,6 +114,11 @@ client: limits: cpu: "2" memory: "4Gi" + tolerations: + - key: "role" + operator: "Equal" + value: "worker" + effect: "NoSchedule" extraVolumeMounts: - name: logs mountPath: "/var/log/" diff --git a/test/testdata/kind/config-v2-nydus.yaml b/test/testdata/kind/config-v2-nydus.yaml new file mode 100644 index 00000000000..030b79c88b0 --- /dev/null +++ b/test/testdata/kind/config-v2-nydus.yaml @@ -0,0 +1,24 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +networking: + ipFamily: dual +nodes: + - role: control-plane + image: kindest/node:v1.23.4 + extraPortMappings: + - containerPort: 4001 + hostPort: 4001 + protocol: TCP + - containerPort: 4003 + hostPort: 4003 + protocol: TCP + - containerPort: 30802 + hostPort: 8002 + protocol: TCP + extraMounts: + - hostPath: ./test/testdata/containerd/config-v2.toml + containerPath: /etc/containerd/config.toml + - hostPath: /tmp/artifact + containerPath: /tmp/artifact + - hostPath: /dev/fuse + containerPath: /dev/fuse diff --git a/test/testdata/kind/config-v2.yaml b/test/testdata/kind/config-v2.yaml index 030b79c88b0..99e971c5679 100644 --- a/test/testdata/kind/config-v2.yaml +++ b/test/testdata/kind/config-v2.yaml @@ -22,3 +22,12 @@ nodes: containerPath: /tmp/artifact - hostPath: /dev/fuse containerPath: /dev/fuse + - role: worker + image: kindest/node:v1.23.4 + extraMounts: + - hostPath: ./test/testdata/containerd/config-v2.toml + containerPath: /etc/containerd/config.toml + - hostPath: /tmp/artifact + containerPath: /tmp/artifact + - hostPath: /dev/fuse + containerPath: /dev/fuse