Skip to content

Commit

Permalink
merge with development
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Oct 21, 2024
2 parents c9c612e + 1ab6076 commit e08c019
Show file tree
Hide file tree
Showing 26 changed files with 261 additions and 382 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/grid-client-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,15 @@ jobs:
run: |
go mod download
- name: install curl, wg and yggdrasil and add peers
- name: install curl, wg and mycelium and add peers
run: |
sudo apt-get update
sudo apt-get install -y wireguard
sudo apt-get install dirmngr
sudo apt-get install curl
gpg --fetch-keys https://neilalexander.s3.dualstack.eu-west-2.amazonaws.com/deb/key.txt
gpg --export 569130E8CA20FBC4CB3FDE555898470A764B32C9 | sudo apt-key add -
echo 'deb http://neilalexander.s3.dualstack.eu-west-2.amazonaws.com/deb/ debian yggdrasil' | sudo tee /etc/apt/sources.list.d/yggdrasil.list
sudo apt-get update
sudo apt-get install yggdrasil
sudo systemctl enable yggdrasil
PEERS=$(curl https://raw.githubusercontent.com/AhmedHanafy725/yggdrasil-config/main/config.json | jq '.yggdrasil.peers[]' -r | sed 's/\//\\\//g' | sed -z 's/\n/\\n/g')
sudo sed -i -- 's/Peers\: \[\]/Peers: [\n'"$PEERS"']/g' /etc/yggdrasil/yggdrasil.conf
sudo systemctl stop yggdrasil
sudo systemctl start yggdrasil
wget https://github.com/threefoldtech/mycelium/releases/download/v0.5.4/mycelium-x86_64-unknown-linux-musl.tar.gz
tar xzf mycelium-x86_64-unknown-linux-musl.tar.gz
sudo ./mycelium --peers tcp://188.40.132.242:9651 quic://185.69.166.8:9651 --tun-name utun9 -k /tmp/mycelium_priv_key.bin &
- name: Test
env:
Expand Down
7 changes: 0 additions & 7 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,6 @@ go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6m
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
Expand All @@ -1047,16 +1045,11 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk=
Expand Down
2 changes: 2 additions & 0 deletions grid-cli/cmd/add_worker_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ var addWorkerCmd = &cobra.Command{
}
}

vm := *worker.VM
worker.VM = &vm
worker.Name = fmt.Sprintf("worker%d", len(workers))
worker.NodeID = uint32(workersNodes[i])
worker.MyceliumIPSeed = seed
Expand Down
3 changes: 2 additions & 1 deletion grid-cli/internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ func AddWorkersKubernetesCluster(ctx context.Context, t deployer.TFPluginClient,
return workloads.K8sCluster{}, err
}

for _, worker := range workers {
for i, worker := range workers {
if !slices.Contains(network.Nodes, worker.NodeID) {
network.Nodes = append(network.Nodes, worker.NodeID)
}
cluster.Workers[i].NetworkName = network.Name
}

if addMycelium {
Expand Down
2 changes: 1 addition & 1 deletion grid-client/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PWD := $(shell pwd)
GOPATH := $(shell go env GOPATH)
integration_tests := $(shell go run scripts/scrap_tests.go)
integration_tests := $(shell go run scripts/scrap_tests/scrap_tests.go)

all: verifiers test

Expand Down
25 changes: 8 additions & 17 deletions grid-client/integration_tests/batch_gateway_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,11 @@ func TestBatchGatewayNameDeployment(t *testing.T) {
nodeID1 := uint32(nodes[0].NodeID)
nodeID2 := uint32(nodes[1].NodeID)

network := generateBasicNetwork([]uint32{nodeID1, nodeID2})

vm := workloads.VM{
Name: "vm",
NodeID: nodeID1,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
}
network, err := generateBasicNetwork([]uint32{nodeID1, nodeID2})
require.NoError(t, err)

vm, err := generateBasicVM("vm", nodeID1, network.Name, publicKey)
require.NoError(t, err)

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
require.NoError(t, err)
Expand All @@ -79,7 +69,7 @@ func TestBatchGatewayNameDeployment(t *testing.T) {
v, err := tfPluginClient.State.LoadVMFromGrid(context.Background(), nodeID1, vm.Name, dl.Name)
require.NoError(t, err)

backend := fmt.Sprintf("http://[%s]:9000", v.PlanetaryIP)
backend := fmt.Sprintf("http://[%s]:9000", v.MyceliumIP)
gw1 := workloads.GatewayNameProxy{
NodeID: nodeID1,
Name: generateRandString(10),
Expand Down Expand Up @@ -113,7 +103,8 @@ func TestBatchGatewayNameDeployment(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, g2.FQDN)

_, err = RemoteRun("root", v.PlanetaryIP, "apk add python3; python3 -m http.server 9000 --bind :: &> /dev/null &", privateKey)
require.NotEmpty(t, v.MyceliumIP)
_, err = RemoteRun("root", v.MyceliumIP, "apk add python3; python3 -m http.server 9000 --bind :: &> /dev/null &", privateKey)
require.NoError(t, err)

time.Sleep(3 * time.Second)
Expand Down
68 changes: 25 additions & 43 deletions grid-client/integration_tests/batch_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func TestBatchK8sDeployment(t *testing.T) {
nodeID1 := uint32(nodes[0].NodeID)
nodeID2 := uint32(nodes[1].NodeID)

network := generateBasicNetwork([]uint32{nodeID1, nodeID2})
network, err := generateBasicNetwork([]uint32{nodeID1, nodeID2})
require.NoError(t, err)

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
require.NoError(t, err)
Expand All @@ -45,57 +46,38 @@ func TestBatchK8sDeployment(t *testing.T) {
require.NoError(t, err)
})

master1VM, err := generateBasicVM(generateRandString(10), nodeID1, network.Name, "")
require.NoError(t, err)

master1 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID1,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
},
VM: &master1VM,
DiskSizeGB: 1,
}
master2VM, err := generateBasicVM(generateRandString(10), nodeID2, network.Name, "")
require.NoError(t, err)

master2 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID2,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
},
VM: &master2VM,
DiskSizeGB: 1,
}
vm1, err := generateBasicVM(generateRandString(10), nodeID1, network.Name, "")
require.NoError(t, err)

workerNodeData1 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID1,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
},
worker1NodeData := workloads.K8sNode{
VM: &vm1,
DiskSizeGB: 1,
}
vm2, err := generateBasicVM(generateRandString(10), nodeID2, network.Name, "")
require.NoError(t, err)

workerNodeData2 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID2,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
},
worker2NodeData := workloads.K8sNode{
VM: &vm2,
DiskSizeGB: 1,
}

k8sCluster1 := workloads.K8sCluster{
Master: &master1,
Workers: []workloads.K8sNode{workerNodeData1},
Workers: []workloads.K8sNode{worker1NodeData},
Token: "tokens",
SSHKey: publicKey,
Flist: workloads.K8sFlist,
Expand All @@ -104,7 +86,7 @@ func TestBatchK8sDeployment(t *testing.T) {

k8sCluster2 := workloads.K8sCluster{
Master: &master2,
Workers: []workloads.K8sNode{workerNodeData2},
Workers: []workloads.K8sNode{worker2NodeData},
Token: "tokens",
SSHKey: publicKey,
Flist: workloads.K8sFlist,
Expand All @@ -130,14 +112,14 @@ func TestBatchK8sDeployment(t *testing.T) {
require.Equal(t, len(k1.Workers), 1)

// Check that master is reachable
require.NotEmpty(t, k1.Master.PlanetaryIP)
require.NotEmpty(t, k1.Master.MyceliumIP)
require.NotEmpty(t, k1.Master.IP)
require.NotEqual(t, k1.Master.IP, k1.Workers[0].IP)

require.True(t, CheckConnection(k1.Workers[0].PlanetaryIP, "22"))
require.True(t, CheckConnection(k1.Workers[0].MyceliumIP, "22"))

// ssh to master node
require.NoError(t, requireNodesAreReady(len(k1.Workers)+1, k1.Master.PlanetaryIP, privateKey))
require.NoError(t, requireNodesAreReady(len(k1.Workers)+1, k1.Master.MyceliumIP, privateKey))

// cluster 2
k2, err := tfPluginClient.State.LoadK8sFromGrid(context.Background(), []uint32{nodeID2}, k8sCluster2.Master.Name)
Expand All @@ -147,14 +129,14 @@ func TestBatchK8sDeployment(t *testing.T) {
require.Equal(t, len(k2.Workers), 1)

// Check that master is reachable
require.NotEmpty(t, k1.Master.PlanetaryIP)
require.NotEmpty(t, k1.Master.MyceliumIP)
require.NotEmpty(t, k1.Master.IP)
require.NotEqual(t, k1.Master.IP, k2.Workers[0].IP)

require.True(t, CheckConnection(k2.Workers[0].PlanetaryIP, "22"))
require.True(t, CheckConnection(k2.Workers[0].MyceliumIP, "22"))

// ssh to master node
require.NoError(t, requireNodesAreReady(len(k2.Workers)+1, k2.Master.PlanetaryIP, privateKey))
require.NoError(t, requireNodesAreReady(len(k2.Workers)+1, k2.Master.MyceliumIP, privateKey))

// different ips generated
require.Equal(t, len(slices.Compact[[]string, string]([]string{k1.Master.IP, k2.Master.IP, k1.Workers[0].IP, k2.Workers[0].IP})), 4)
Expand Down
47 changes: 14 additions & 33 deletions grid-client/integration_tests/batch_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,17 @@ func TestBatchVMDeployment(t *testing.T) {
nodeID1 := uint32(nodes[0].NodeID)
nodeID2 := uint32(nodes[1].NodeID)

network1 := generateBasicNetwork([]uint32{nodeID1})
network2 := generateBasicNetwork([]uint32{nodeID2})

vm1 := workloads.VM{
Name: "vm",
NodeID: nodeID1,
NetworkName: network1.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
}
network1, err := generateBasicNetwork([]uint32{nodeID1})
require.NoError(t, err)

vm2 := workloads.VM{
Name: "vm",
NodeID: nodeID2,
NetworkName: network2.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
}
network2, err := generateBasicNetwork([]uint32{nodeID2})
require.NoError(t, err)

vm1, err := generateBasicVM("vm", nodeID1, network1.Name, publicKey)
require.NoError(t, err)

vm2, err := generateBasicVM("vm", nodeID2, network2.Name, publicKey)
require.NoError(t, err)

err = tfPluginClient.NetworkDeployer.BatchDeploy(context.Background(), []workloads.Network{&network1, &network2})
require.NoError(t, err)
Expand Down Expand Up @@ -93,17 +74,17 @@ func TestBatchVMDeployment(t *testing.T) {

v1, err := tfPluginClient.State.LoadVMFromGrid(context.Background(), nodeID1, vm1.Name, dl1.Name)
require.NoError(t, err)
require.NotEmpty(t, v1.PlanetaryIP)
require.NotEmpty(t, v1.MyceliumIP)

output, err := RemoteRun("root", v1.PlanetaryIP, "ls /", privateKey)
output, err := RemoteRun("root", v1.MyceliumIP, "ls /", privateKey)
require.NoError(t, err)
require.Contains(t, output, "root")

v2, err := tfPluginClient.State.LoadVMFromGrid(context.Background(), nodeID2, vm2.Name, dl2.Name)
require.NoError(t, err)
require.NotEmpty(t, v2.PlanetaryIP)
require.NotEmpty(t, v2.MyceliumIP)

output, err = RemoteRun("root", v2.PlanetaryIP, "ls /", privateKey)
output, err = RemoteRun("root", v2.MyceliumIP, "ls /", privateKey)
require.NoError(t, err)
require.Contains(t, output, "root")
}
23 changes: 6 additions & 17 deletions grid-client/integration_tests/gateway_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,10 @@ func TestGatewayNameDeployment(t *testing.T) {

nodeID := uint32(nodes[0].NodeID)

network := generateBasicNetwork([]uint32{nodeID})

vm := workloads.VM{
Name: "vm",
NodeID: nodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
}
network, err := generateBasicNetwork([]uint32{nodeID})
require.NoError(t, err)
vm, err := generateBasicVM("vm", nodeID, network.Name, publicKey)
require.NoError(t, err)

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
require.NoError(t, err)
Expand All @@ -92,7 +81,7 @@ func TestGatewayNameDeployment(t *testing.T) {
v, err := tfPluginClient.State.LoadVMFromGrid(context.Background(), nodeID, vm.Name, dl.Name)
require.NoError(t, err)

backend := fmt.Sprintf("http://[%s]:9000", v.PlanetaryIP)
backend := fmt.Sprintf("http://[%s]:9000", v.MyceliumIP)
gw := workloads.GatewayNameProxy{
NodeID: gwNodeID,
Name: generateRandString(10),
Expand All @@ -112,7 +101,7 @@ func TestGatewayNameDeployment(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, result.FQDN)

_, err = RemoteRun("root", v.PlanetaryIP, "apk add python3; python3 -m http.server 9000 --bind :: &> /dev/null &", privateKey)
_, err = RemoteRun("root", v.MyceliumIP, "apk add python3; python3 -m http.server 9000 --bind :: &> /dev/null &", privateKey)
require.NoError(t, err)

time.Sleep(3 * time.Second)
Expand Down
Loading

0 comments on commit e08c019

Please sign in to comment.