Skip to content

Commit

Permalink
fix: change the offline client from seed peer to peer
Browse files Browse the repository at this point in the history
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
  • Loading branch information
BruceAko committed Oct 6, 2024
1 parent 9d252a5 commit 18a5fdd
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-v2-nydus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/e2e-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
110 changes: 110 additions & 0 deletions scheduler/service/service_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/v2/leave_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ 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()
fmt.Println(string(out))
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()
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/v2/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ var Servers = map[string]server{
Name: ClientServerName,
Namespace: DragonflyNamespace,
LogDirName: "dfdaemon",
Replicas: 1,
Replicas: 2,
},
}
6 changes: 3 additions & 3 deletions test/e2e/v2/util/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions test/testdata/charts/config-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
24 changes: 24 additions & 0 deletions test/testdata/kind/config-v2-nydus.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions test/testdata/kind/config-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 18a5fdd

Please sign in to comment.