Skip to content

Commit fcd7313

Browse files
authored
Merge pull request #637 from codescalers/development_mycelium
support mycelium in server and client
2 parents c2974e6 + c220db3 commit fcd7313

7 files changed

Lines changed: 127 additions & 53 deletions

File tree

client/src/views/K8s.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@
171171
@click="copyIP(item.master.ygg_ip)"
172172
>
173173
{{ item.master.ygg_ip }}
174+
</td>
175+
<td
176+
class="cursor-pointer"
177+
@click="copyIP(item.master.mycelium_ip)"
178+
>
179+
{{ item.master.mycelium_ip }}
174180
</td>
175181
<td
176182
v-if="item.master.public_ip"
@@ -205,7 +211,7 @@
205211
</template>
206212
</v-data-table>
207213
<v-dialog transition="dialog-top-transition" v-model="dialog">
208-
<v-card width="50%" class="mx-auto">
214+
<v-card width="60%" class="mx-auto">
209215
<v-toolbar color="transparent">
210216
<v-spacer></v-spacer>
211217
<v-toolbar-items>
@@ -302,6 +308,11 @@ export default {
302308
key: "ygg_ip",
303309
sortable: false,
304310
},
311+
{
312+
title: "Mycelium IP",
313+
key: "mycelium_ip",
314+
sortable: false,
315+
},
305316
{
306317
title: "Public IP",
307318
key: "public_ip",
@@ -337,10 +348,15 @@ export default {
337348
sortable: false,
338349
},
339350
{
340-
title: "Resources",
341-
key: "resources",
351+
title: "Yggdrasil IP",
352+
key: "ygg_ip",
342353
sortable: false,
343354
},
355+
{
356+
title: "Mycelium IP",
357+
key: "mycelium_ip",
358+
sortable: false,
359+
}
344360
]);
345361
const resources = ref([
346362
{ title: "Small K8s (1 CPU, 2GB, 25GB)", value: "small" },

client/src/views/VM.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
<td class="cursor-pointer" @click="copyIP(item.ygg_ip)">
7272
{{ item.ygg_ip }}
7373
</td>
74+
<td class="cursor-pointer" @click="copyIP(item.mycelium_ip)">
75+
{{ item.mycelium_ip }}
76+
</td>
7477
<td
7578
v-if="item.public_ip"
7679
class="cursor-pointer"
@@ -172,6 +175,11 @@ export default {
172175
key: "ygg_ip",
173176
sortable: false,
174177
},
178+
{
179+
title: "Mycelium IP",
180+
key: "mycelium_ip",
181+
sortable: false,
182+
},
175183
{
176184
title: "Public IP",
177185
key: "public_ip",

server/deployer/deployer.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,22 @@ func (d *Deployer) CancelDeployment(contractID uint64, netContractID uint64, dlT
164164
return nil
165165
}
166166

167-
func buildNetwork(node uint32, name string) workloads.ZNet {
167+
func buildNetwork(node uint32, name string) (workloads.ZNet, error) {
168+
myceliumKey, err := workloads.RandomMyceliumKey()
169+
if err != nil {
170+
return workloads.ZNet{}, err
171+
}
172+
168173
return workloads.ZNet{
169174
Name: name,
170175
Nodes: []uint32{node},
171176
IPRange: workloads.NewIPRange(net.IPNet{
172177
IP: net.IPv4(10, 20, 0, 0),
173178
Mask: net.CIDRMask(16, 32),
174179
}),
175-
AddWGAccess: false,
176-
}
180+
AddWGAccess: false,
181+
MyceliumKeys: map[uint32][]byte{node: myceliumKey},
182+
}, nil
177183
}
178184

179185
func calcNodeResources(resources string, public bool) (uint64, uint64, uint64, uint64, error) {

server/deployer/k8s_deployer.go

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,27 @@ import (
1818
)
1919

2020
func buildK8sCluster(node uint32, sshKey, network string, k models.K8sDeployInput) (workloads.K8sCluster, error) {
21+
myceliumIPSeed, err := workloads.RandomMyceliumIPSeed()
22+
if err != nil {
23+
return workloads.K8sCluster{}, err
24+
}
25+
2126
master := workloads.K8sNode{
2227
VM: &workloads.VM{
23-
Name: k.MasterName,
24-
Flist: k8sFlist,
25-
Planetary: true,
26-
NodeID: node,
27-
NetworkName: network,
28+
Name: k.MasterName,
29+
Flist: k8sFlist,
30+
Planetary: true,
31+
MyceliumIPSeed: myceliumIPSeed,
32+
NodeID: node,
33+
NetworkName: network,
2834
},
2935
}
36+
3037
cru, mru, sru, ips, err := calcNodeResources(k.Resources, k.Public)
3138
if err != nil {
3239
return workloads.K8sCluster{}, err
3340
}
41+
3442
master.CPU = uint8(cru)
3543
master.MemoryMB = mru * 1024
3644
master.DiskSizeGB = sru
@@ -40,23 +48,33 @@ func buildK8sCluster(node uint32, sshKey, network string, k models.K8sDeployInpu
4048

4149
workers := []workloads.K8sNode{}
4250
for _, worker := range k.Workers {
51+
myceliumIPSeed, err := workloads.RandomMyceliumIPSeed()
52+
if err != nil {
53+
return workloads.K8sCluster{}, err
54+
}
55+
4356
w := workloads.K8sNode{
4457
VM: &workloads.VM{
45-
Name: worker.Name,
46-
Flist: k8sFlist,
47-
NodeID: node,
48-
NetworkName: network,
58+
Name: worker.Name,
59+
Flist: k8sFlist,
60+
NodeID: node,
61+
NetworkName: network,
62+
Planetary: true,
63+
MyceliumIPSeed: myceliumIPSeed,
4964
},
5065
}
66+
5167
cru, mru, sru, _, err := calcNodeResources(k.Resources, false)
5268
if err != nil {
5369
return workloads.K8sCluster{}, err
5470
}
71+
5572
w.CPU = uint8(cru)
5673
w.MemoryMB = mru * 1024
5774
w.DiskSizeGB = sru
5875
workers = append(workers, w)
5976
}
77+
6078
k8sCluster := workloads.K8sCluster{
6179
Master: &master,
6280
Workers: workers,
@@ -77,7 +95,10 @@ func (d *Deployer) deployK8sClusterWithNetwork(ctx context.Context, k8sDeployInp
7795
}
7896

7997
// build network
80-
network := buildNetwork(node, fmt.Sprintf("%sk8sNet", k8sDeployInput.MasterName))
98+
network, err := buildNetwork(node, fmt.Sprintf("%sk8sNet", k8sDeployInput.MasterName))
99+
if err != nil {
100+
return 0, 0, 0, err
101+
}
81102

82103
// build cluster
83104
cluster, err := buildK8sCluster(node,
@@ -128,29 +149,36 @@ func (d *Deployer) loadK8s(ctx context.Context, k8sDeployInput models.K8sDeployI
128149
if err != nil {
129150
return models.K8sCluster{}, err
130151
}
152+
131153
master := models.Master{
132-
CRU: cru,
133-
MRU: mru,
134-
SRU: sru,
135-
Public: k8sDeployInput.Public,
136-
PublicIP: resCluster.Master.ComputedIP,
137-
Name: k8sDeployInput.MasterName,
138-
YggIP: resCluster.Master.PlanetaryIP,
139-
Resources: k8sDeployInput.Resources,
154+
CRU: cru,
155+
MRU: mru,
156+
SRU: sru,
157+
Public: k8sDeployInput.Public,
158+
PublicIP: resCluster.Master.ComputedIP,
159+
Name: k8sDeployInput.MasterName,
160+
YggIP: resCluster.Master.PlanetaryIP,
161+
MyceliumIP: resCluster.Master.MyceliumIP,
162+
Resources: k8sDeployInput.Resources,
140163
}
141-
workers := []models.Worker{}
142-
for _, worker := range k8sDeployInput.Workers {
143164

165+
workers := []models.Worker{}
166+
for i, worker := range k8sDeployInput.Workers {
144167
cru, mru, sru, _, err := calcNodeResources(worker.Resources, false)
145168
if err != nil {
146169
return models.K8sCluster{}, err
147170
}
171+
148172
workerModel := models.Worker{
149-
Name: worker.Name,
150-
CRU: cru,
151-
MRU: mru,
152-
SRU: sru,
153-
Resources: worker.Resources,
173+
Name: worker.Name,
174+
CRU: cru,
175+
MRU: mru,
176+
SRU: sru,
177+
Public: k8sDeployInput.Public,
178+
PublicIP: resCluster.Workers[i].ComputedIP,
179+
YggIP: resCluster.Workers[i].PlanetaryIP,
180+
MyceliumIP: resCluster.Workers[i].MyceliumIP,
181+
Resources: worker.Resources,
154182
}
155183
workers = append(workers, workerModel)
156184
}

server/deployer/vms_deployer.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,31 @@ func (d *Deployer) deployVM(ctx context.Context, vmInput models.DeployVMInput, s
4343
nodeID := uint32(nodeIDs[0].NodeID)
4444

4545
// create network workload
46-
network := buildNetwork(nodeID, fmt.Sprintf("%svmNet", vmInput.Name))
46+
network, err := buildNetwork(nodeID, fmt.Sprintf("%svmNet", vmInput.Name))
47+
if err != nil {
48+
return nil, 0, 0, 0, err
49+
}
4750

4851
// create disk
4952
disk := workloads.Disk{
5053
Name: "disk",
5154
SizeGB: sru,
5255
}
5356

57+
myceliumIPSeed, err := workloads.RandomMyceliumIPSeed()
58+
if err != nil {
59+
return nil, 0, 0, 0, err
60+
}
61+
5462
// create vm workload
5563
vm := workloads.VM{
56-
Name: vmInput.Name,
57-
Flist: vmFlist,
58-
CPU: uint8(*filter.TotalCRU),
59-
PublicIP: vmInput.Public,
60-
Planetary: true,
61-
MemoryMB: mru * 1024,
64+
Name: vmInput.Name,
65+
Flist: vmFlist,
66+
CPU: uint8(*filter.TotalCRU),
67+
PublicIP: vmInput.Public,
68+
Planetary: true,
69+
MyceliumIPSeed: myceliumIPSeed,
70+
MemoryMB: mru * 1024,
6271
Mounts: []workloads.Mount{
6372
{Name: disk.Name, MountPoint: "/disk"},
6473
},
@@ -143,6 +152,7 @@ func (d *Deployer) deployVMRequest(ctx context.Context, user models.User, input
143152
UserID: user.ID.String(),
144153
Name: vm.Name,
145154
YggIP: vm.PlanetaryIP,
155+
MyceliumIP: vm.MyceliumIP,
146156
Resources: input.Resources,
147157
Public: input.Public,
148158
PublicIP: vm.ComputedIP,

server/models/k8s.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,28 @@ type K8sCluster struct {
1313

1414
// Master struct for kubernetes master data
1515
type Master struct {
16-
ClusterID int `json:"clusterID"`
17-
Name string `json:"name" gorm:"unique" binding:"required"`
18-
CRU uint64 `json:"cru"`
19-
MRU uint64 `json:"mru"`
20-
SRU uint64 `json:"sru"`
21-
YggIP string `json:"ygg_ip"`
22-
Public bool `json:"public"`
23-
PublicIP string `json:"public_ip"`
24-
Resources string `json:"resources"`
16+
ClusterID int `json:"clusterID"`
17+
Name string `json:"name" gorm:"unique" binding:"required"`
18+
CRU uint64 `json:"cru"`
19+
MRU uint64 `json:"mru"`
20+
SRU uint64 `json:"sru"`
21+
YggIP string `json:"ygg_ip"`
22+
MyceliumIP string `json:"mycelium_ip"`
23+
Public bool `json:"public"`
24+
PublicIP string `json:"public_ip"`
25+
Resources string `json:"resources"`
2526
}
2627

2728
// Worker struct for k8s workers data
2829
type Worker struct {
29-
ClusterID int `json:"clusterID"`
30-
Name string `json:"name"`
31-
CRU uint64 `json:"cru"`
32-
MRU uint64 `json:"mru"`
33-
SRU uint64 `json:"sru"`
34-
Resources string `json:"resources"`
30+
ClusterID int `json:"clusterID"`
31+
Name string `json:"name"`
32+
CRU uint64 `json:"cru"`
33+
MRU uint64 `json:"mru"`
34+
SRU uint64 `json:"sru"`
35+
YggIP string `json:"ygg_ip"`
36+
MyceliumIP string `json:"mycelium_ip"`
37+
Public bool `json:"public"`
38+
PublicIP string `json:"public_ip"`
39+
Resources string `json:"resources"`
3540
}

server/models/vm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type VM struct {
77
UserID string `json:"user_id"`
88
Name string `json:"name" gorm:"unique" binding:"required"`
99
YggIP string `json:"ygg_ip"`
10+
MyceliumIP string `json:"mycelium_ip"`
1011
Public bool `json:"public"`
1112
PublicIP string `json:"public_ip"`
1213
Resources string `json:"resources"`

0 commit comments

Comments
 (0)