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 13 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
22 changes: 9 additions & 13 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
workersNode, err := cmd.Flags().GetUintSlice("workers-node")
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,12 +185,10 @@ var deployKubernetesCmd = &cobra.Command{
masterNode = uint32(nodes[0].NodeID)
}
master.Node = masterNode
if workersNode == 0 && len(workers) > 0 {

if len(workersNode) < workerNumber && workerNumber > 0 {
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(
Nabil-Salah marked this conversation as resolved.
Show resolved Hide resolved
cmd.Context(),
Expand All @@ -200,19 +197,18 @@ var deployKubernetesCmd = &cobra.Command{
disks,
nil,
rootfss,
uint64(len(workers)),
uint64(workerNumber-len(workersNode)),
)
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 i := 0; i < len(workersNodes); i++ {
workersNode = append(workersNode, uint(workersNodes[i].NodeID))
}
}
for i := 0; i < workerNumber; i++ {
workers[i].Node = uint32(workersNode[i])
}
cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey))
if err != nil {
log.Fatal().Err(err).Send()
Expand Down Expand Up @@ -283,7 +279,7 @@ 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-node", []uint{0}, "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.Flags().Bool("workers-ipv4", false, "assign public ipv4 for workers")
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