Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development support deploying k8s workers on multiple nodes #1136

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grid-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Login using your mnemonics and specify which grid network (mainnet/testnet) to d
tfcmd login
```

Check [Wallet Connector](https://manual.grid.tf/dashboard/wallet_connector.html) for more details if you do not have mnemonics yet.
Check [Wallet Connector](https://manual.grid.tf/documentation/dashboard/wallet_connector.html) for more details if you do not have mnemonics yet.

For examples and description of tfcmd commands check out:

Expand Down
26 changes: 11 additions & 15 deletions grid-cli/cmd/deploy_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var deployKubernetesCmd = &cobra.Command{
return err
}

workersNode, err := cmd.Flags().GetUint32("workers-node")
Nabil-Salah marked this conversation as resolved.
Show resolved Hide resolved
workersNodes, err := cmd.Flags().GetUintSlice("workers-nodes")
if err != nil {
return err
}
Expand Down Expand Up @@ -169,7 +169,6 @@ var deployKubernetesCmd = &cobra.Command{
filter, disks, rootfss := filters.BuildK8sFilter(
master,
masterFarm,
1,
)
nodes, err := deployer.FilterNodes(
cmd.Context(),
Expand All @@ -186,33 +185,30 @@ var deployKubernetesCmd = &cobra.Command{
masterNode = uint32(nodes[0].NodeID)
}
master.Node = masterNode
if workersNode == 0 && len(workers) > 0 {

if len(workersNodes) < workerNumber {
Eslam-Nawara marked this conversation as resolved.
Show resolved Hide resolved
filter, disks, rootfss := filters.BuildK8sFilter(
Nabil-Salah marked this conversation as resolved.
Show resolved Hide resolved
workers[0],
Nabil-Salah marked this conversation as resolved.
Show resolved Hide resolved
workersFarm,
uint(len(workers)),
)
workersNodes, err := deployer.FilterNodes(
nodes, err := deployer.FilterNodes(
cmd.Context(),
t,
filter,
disks,
nil,
rootfss,
uint64(len(workers)),
uint64(workerNumber-len(workersNodes)),
)
if err != nil {
log.Fatal().Err(err).Send()
}
for i, node := range workersNodes {
workers[i].Node = uint32(node.NodeID)
}
} else {
for i := 0; i < workerNumber; i++ {
workers[i].Node = workersNode
for _, node := range nodes {
workersNodes = append(workersNodes, uint(node.NodeID))
}
}
for i, node := range workersNodes {
workers[i].Node = uint32(node)
}
cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey))
if err != nil {
log.Fatal().Err(err).Send()
Expand Down Expand Up @@ -283,9 +279,9 @@ func init() {
deployKubernetesCmd.Flags().Int("workers-cpu", 1, "workers number of cpu units")
deployKubernetesCmd.Flags().Int("workers-memory", 1, "workers memory size in gb")
deployKubernetesCmd.Flags().Int("workers-disk", 2, "workers disk size in gb")
deployKubernetesCmd.Flags().Uint32("workers-node", 0, "node id workers should be deployed on")
Nabil-Salah marked this conversation as resolved.
Show resolved Hide resolved
deployKubernetesCmd.Flags().UintSlice("workers-nodes", []uint{}, "node id workers should be deployed on")
deployKubernetesCmd.Flags().Uint64("workers-farm", 1, "farm id workers should be deployed on")
deployKubernetesCmd.MarkFlagsMutuallyExclusive("workers-node", "workers-farm")
deployKubernetesCmd.MarkFlagsMutuallyExclusive("workers-nodes", "workers-farm")
deployKubernetesCmd.Flags().Bool("workers-ipv4", false, "assign public ipv4 for workers")
deployKubernetesCmd.Flags().Bool("workers-ipv6", false, "assign public ipv6 for workers")
deployKubernetesCmd.Flags().Bool("workers-ygg", true, "assign yggdrasil ip for workers")
Expand Down
4 changes: 2 additions & 2 deletions grid-cli/docs/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tfcmd deploy kubernetes [flags]

- master-node: node id master should be deployed on.
- master-farm: farm id master should be deployed on, if set choose available node from farm that fits master specs (default 1). note: master-node and master-farm flags cannot be set both.
- workers-node: node id workers should be deployed on.
- workers-nodes: array of nodes ids workers should be deployed on and the remaining unassigned workers will be randomly assigned to nodes that meet the specifications.
- workers-farm: farm id workers should be deployed on, if set choose available node from farm that fits master specs (default 1). note: workers-node and workers-farm flags cannot be set both.
- ipv4: assign public ipv4 for master node (default false).
- ipv6: assign public ipv6 for master node (default false).
Expand All @@ -38,7 +38,7 @@ tfcmd deploy kubernetes [flags]
Example:

```console
$ tfcmd deploy kubernetes -n kube --ssh ~/.ssh/id_rsa.pub --master-node 14 --workers-number 2 --workers-node 14
$ tfcmd deploy kubernetes -n kube --ssh ~/.ssh/id_rsa.pub --master-node 14 --workers-number 2 --workers-nodes 14,1
11:43AM INF starting peer session=tf-1510734 twin=192
11:43AM INF deploying network
11:43AM INF deploying cluster
Expand Down
20 changes: 8 additions & 12 deletions grid-cli/internal/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import (
)

// BuildK8sFilter build a filter for a k8s node
func BuildK8sFilter(k8sNode workloads.K8sNode, farmID uint64, k8sNodesNum uint) (types.NodeFilter, []uint64, []uint64) {
freeMRUs := uint64(k8sNode.Memory*int(k8sNodesNum)) / 1024
freeSRUs := uint64(k8sNode.DiskSize * int(k8sNodesNum))
func BuildK8sFilter(k8sNode workloads.K8sNode, farmID uint64) (types.NodeFilter, []uint64, []uint64) {
freeMRUs := uint64(k8sNode.Memory) / 1024
freeSRUs := uint64(k8sNode.DiskSize)
freeIPs := uint64(0)
if k8sNode.PublicIP {
freeIPs = uint64(k8sNodesNum)
}
Nabil-Salah marked this conversation as resolved.
Show resolved Hide resolved

disks := make([]uint64, k8sNodesNum)
rootfss := make([]uint64, k8sNodesNum)
for i := 0; i < int(k8sNodesNum); i++ {
disks = append(disks, *convertGBToBytes(uint64(k8sNode.DiskSize)))
// k8s rootfs is either 2 or 0.5
rootfss = append(rootfss, *convertGBToBytes(uint64(2)))
if k8sNode.PublicIP {
freeIPs = uint64(1)
}
disks := []uint64{*convertGBToBytes(uint64(k8sNode.DiskSize))}
// k8s rootfs is either 2 or 0.5
rootfss := []uint64{*convertGBToBytes(uint64(2))}

return buildGenericFilter(&freeMRUs, &freeSRUs, nil, &freeIPs, []uint64{farmID}, nil), disks, rootfss
}
Expand Down
Loading