From b9d22756984a023ddf039c010afc12b63663a561 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Mon, 29 Jul 2024 17:03:03 +0300 Subject: [PATCH 01/20] feat: add feature to allow user to add multiple nodes to deploy workers --- grid-cli/cmd/deploy_kubernetes.go | 38 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 95796f540..9fb15ce8f 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -4,6 +4,8 @@ package cmd import ( "fmt" "os" + "strconv" + "strings" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -16,6 +18,28 @@ import ( var k8sFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist" + +func stringToIntArray(s string)( []uint32, error){ + + s = strings.TrimSpace(s) + if len(s) <= 0 { + return make([]uint32,0),fmt.Errorf("error parsing the worker nodes number") + } + nodesMapped := strings.Split(s," ") + parsedNodes := []uint32{} + for _,num := range nodesMapped { + numParsed ,err := strconv.ParseUint(num, 10, 32) + if err != nil { + return make([]uint32,0),fmt.Errorf("error parsing the worker nodes number") + } + parsedNodes = append(parsedNodes, uint32(numParsed)) + } + if len(parsedNodes) <= 0 { + return make([]uint32,0),fmt.Errorf("error parsing the worker nodes umber") + } + return parsedNodes,nil +} + // deployKubernetesCmd represents the deploy kubernetes command var deployKubernetesCmd = &cobra.Command{ Use: "kubernetes", @@ -94,7 +118,11 @@ var deployKubernetesCmd = &cobra.Command{ return err } - workersNode, err := cmd.Flags().GetUint32("workers-node") + workersNodeToParse, err := cmd.Flags().GetString("workers-node") + if err != nil { + return err + } + workersNode,err := stringToIntArray(workersNodeToParse) if err != nil { return err } @@ -186,7 +214,7 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if workersNode == 0 && len(workers) > 0 { + if len(workersNode) < len(workers) { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], @@ -210,7 +238,7 @@ var deployKubernetesCmd = &cobra.Command{ } } else { for i := 0; i < workerNumber; i++ { - workers[i].Node = workersNode + workers[i].Node = workersNode[i%len(workersNode)] } } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) @@ -283,7 +311,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") + deployKubernetesCmd.Flags().String("workers-node", "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") @@ -295,4 +323,4 @@ func init() { deployKubernetesCmd.Flags().Bool("ipv6", false, "assign public ipv6 for master") deployKubernetesCmd.Flags().Bool("ygg", true, "assign yggdrasil ip for master") deployKubernetesCmd.Flags().Bool("mycelium", true, "assign mycelium ip for master") -} +} \ No newline at end of file From a83df5499cee55a5c1058b53abea9fee7eae9ed0 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Mon, 29 Jul 2024 17:11:39 +0300 Subject: [PATCH 02/20] feat: add feature to allow user to add multiple nodes to deploy workers --- grid-cli/cmd/deploy_kubernetes.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 9fb15ce8f..39ad9eea2 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -18,26 +18,25 @@ import ( var k8sFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist" - -func stringToIntArray(s string)( []uint32, error){ +func stringToIntArray(s string) ([]uint32, error) { s = strings.TrimSpace(s) if len(s) <= 0 { - return make([]uint32,0),fmt.Errorf("error parsing the worker nodes number") + return make([]uint32, 0), fmt.Errorf("error parsing the worker nodes number") } - nodesMapped := strings.Split(s," ") + nodesMapped := strings.Split(s, " ") parsedNodes := []uint32{} - for _,num := range nodesMapped { - numParsed ,err := strconv.ParseUint(num, 10, 32) + for _, num := range nodesMapped { + numParsed, err := strconv.ParseUint(num, 10, 32) if err != nil { - return make([]uint32,0),fmt.Errorf("error parsing the worker nodes number") + return make([]uint32, 0), fmt.Errorf("error parsing the worker nodes number") } parsedNodes = append(parsedNodes, uint32(numParsed)) } if len(parsedNodes) <= 0 { - return make([]uint32,0),fmt.Errorf("error parsing the worker nodes umber") + return make([]uint32, 0), fmt.Errorf("error parsing the worker nodes umber") } - return parsedNodes,nil + return parsedNodes, nil } // deployKubernetesCmd represents the deploy kubernetes command @@ -122,7 +121,7 @@ var deployKubernetesCmd = &cobra.Command{ if err != nil { return err } - workersNode,err := stringToIntArray(workersNodeToParse) + workersNode, err := stringToIntArray(workersNodeToParse) if err != nil { return err } @@ -238,7 +237,7 @@ var deployKubernetesCmd = &cobra.Command{ } } else { for i := 0; i < workerNumber; i++ { - workers[i].Node = workersNode[i%len(workersNode)] + workers[i].Node = workersNode[i%len(workersNode)] } } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) @@ -323,4 +322,4 @@ func init() { deployKubernetesCmd.Flags().Bool("ipv6", false, "assign public ipv6 for master") deployKubernetesCmd.Flags().Bool("ygg", true, "assign yggdrasil ip for master") deployKubernetesCmd.Flags().Bool("mycelium", true, "assign mycelium ip for master") -} \ No newline at end of file +} From 4d3254a9e133656425657864cfe56e1e71b3dbc9 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Tue, 30 Jul 2024 11:34:09 +0300 Subject: [PATCH 03/20] fix: using int slice parser --- grid-cli/cmd/deploy_kubernetes.go | 32 +++---------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 39ad9eea2..77285b410 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -4,8 +4,6 @@ package cmd import ( "fmt" "os" - "strconv" - "strings" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -18,26 +16,6 @@ import ( var k8sFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist" -func stringToIntArray(s string) ([]uint32, error) { - - s = strings.TrimSpace(s) - if len(s) <= 0 { - return make([]uint32, 0), fmt.Errorf("error parsing the worker nodes number") - } - nodesMapped := strings.Split(s, " ") - parsedNodes := []uint32{} - for _, num := range nodesMapped { - numParsed, err := strconv.ParseUint(num, 10, 32) - if err != nil { - return make([]uint32, 0), fmt.Errorf("error parsing the worker nodes number") - } - parsedNodes = append(parsedNodes, uint32(numParsed)) - } - if len(parsedNodes) <= 0 { - return make([]uint32, 0), fmt.Errorf("error parsing the worker nodes umber") - } - return parsedNodes, nil -} // deployKubernetesCmd represents the deploy kubernetes command var deployKubernetesCmd = &cobra.Command{ @@ -117,11 +95,7 @@ var deployKubernetesCmd = &cobra.Command{ return err } - workersNodeToParse, err := cmd.Flags().GetString("workers-node") - if err != nil { - return err - } - workersNode, err := stringToIntArray(workersNodeToParse) + workersNode, err := cmd.Flags().GetUintSlice("workers-node") if err != nil { return err } @@ -237,7 +211,7 @@ var deployKubernetesCmd = &cobra.Command{ } } else { for i := 0; i < workerNumber; i++ { - workers[i].Node = workersNode[i%len(workersNode)] + workers[i].Node = uint32(workersNode[i%len(workersNode)]) } } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) @@ -310,7 +284,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().String("workers-node", "0", "node id workers should be deployed on") + deployKubernetesCmd.Flags().UintSlice("workers-node", make([]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") From ba94e3f1e94946ee7b35d4d27fedae1fcb645338 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Tue, 30 Jul 2024 11:36:46 +0300 Subject: [PATCH 04/20] fix: using int slice parser --- grid-cli/cmd/deploy_kubernetes.go | 1 - 1 file changed, 1 deletion(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 77285b410..ba8c7859e 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -16,7 +16,6 @@ import ( var k8sFlist = "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist" - // deployKubernetesCmd represents the deploy kubernetes command var deployKubernetesCmd = &cobra.Command{ Use: "kubernetes", From 392c9e34d6f1a48d033fc973ba433b42aa3ca65a Mon Sep 17 00:00:00 2001 From: nabil salah Date: Tue, 30 Jul 2024 13:46:42 +0300 Subject: [PATCH 05/20] fix: assign unassigned workers only --- grid-cli/cmd/deploy_kubernetes.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index ba8c7859e..0ce76c064 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -186,7 +186,7 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if len(workersNode) < len(workers) { + if len(workersNode) < len(workers) && len(workers) > 0 { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], @@ -200,17 +200,20 @@ var deployKubernetesCmd = &cobra.Command{ disks, nil, rootfss, - uint64(len(workers)), + uint64(len(workers) - len(workersNode)), ) if err != nil { log.Fatal().Err(err).Send() } - for i, node := range workersNodes { - workers[i].Node = uint32(node.NodeID) + for i := 0; i < len(workersNode); i++ { + workers[i].Node = uint32(workersNode[i]) + } + for i, j := len(workersNode),0; i < len(workers); i++ { + workers[i].Node = uint32(workersNodes[j].NodeID) } } else { for i := 0; i < workerNumber; i++ { - workers[i].Node = uint32(workersNode[i%len(workersNode)]) + workers[i].Node = uint32(workersNode[i]) } } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) From b6828307290b0689be2688b1a444f0ff62bc21d4 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Tue, 30 Jul 2024 13:54:10 +0300 Subject: [PATCH 06/20] fix: assign unassigned workers only --- grid-cli/cmd/deploy_kubernetes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 0ce76c064..260173aad 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -200,7 +200,7 @@ var deployKubernetesCmd = &cobra.Command{ disks, nil, rootfss, - uint64(len(workers) - len(workersNode)), + uint64(len(workers)-len(workersNode)), ) if err != nil { log.Fatal().Err(err).Send() @@ -208,7 +208,7 @@ var deployKubernetesCmd = &cobra.Command{ for i := 0; i < len(workersNode); i++ { workers[i].Node = uint32(workersNode[i]) } - for i, j := len(workersNode),0; i < len(workers); i++ { + for i, j := len(workersNode), 0; i < len(workers); i++ { workers[i].Node = uint32(workersNodes[j].NodeID) } } else { From e6d571d8eb7ca6b04c166a61ecfc691de6acfef3 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Tue, 30 Jul 2024 16:11:30 +0300 Subject: [PATCH 07/20] fix: code refactor --- grid-cli/cmd/deploy_kubernetes.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 260173aad..0c6aad587 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -186,12 +186,11 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if len(workersNode) < len(workers) && len(workers) > 0 { - + if len(workersNode)< len(workers) &&len(workers) > 0 { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, - uint(len(workers)), + uint(len(workers)-len(workersNode)), ) workersNodes, err := deployer.FilterNodes( cmd.Context(), @@ -200,22 +199,17 @@ var deployKubernetesCmd = &cobra.Command{ disks, nil, rootfss, - uint64(len(workers)-len(workersNode)), ) if err != nil { log.Fatal().Err(err).Send() } - for i := 0; i < len(workersNode); i++ { - workers[i].Node = uint32(workersNode[i]) - } - for i, j := len(workersNode), 0; i < len(workers); i++ { - workers[i].Node = uint32(workersNodes[j].NodeID) - } - } else { - for i := 0; i < workerNumber; i++ { - workers[i].Node = uint32(workersNode[i]) + for i := 0; i < len(workersNodes); i++ { + workersNode = append(workersNode, uint(workersNodes[i].NodeID) ) } } + for i := 0; i < len(workers); 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() @@ -286,7 +280,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().UintSlice("workers-node", make([]uint, 0), "node id workers should be deployed on") + 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") From 80ee8883018a64300c25db7434e9f12119de6c5a Mon Sep 17 00:00:00 2001 From: nabil salah Date: Tue, 30 Jul 2024 16:24:02 +0300 Subject: [PATCH 08/20] fix: code refactor --- grid-cli/cmd/deploy_kubernetes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 0c6aad587..b547e305c 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -186,7 +186,7 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if len(workersNode)< len(workers) &&len(workers) > 0 { + if len(workersNode) < len(workers) && len(workers) > 0 { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, @@ -204,7 +204,7 @@ var deployKubernetesCmd = &cobra.Command{ log.Fatal().Err(err).Send() } for i := 0; i < len(workersNodes); i++ { - workersNode = append(workersNode, uint(workersNodes[i].NodeID) ) + workersNode = append(workersNode, uint(workersNodes[i].NodeID)) } } for i := 0; i < len(workers); i++ { From 4ae566809738809364e82dbe6351f705658ce79b Mon Sep 17 00:00:00 2001 From: nabil salah Date: Wed, 31 Jul 2024 12:24:36 +0300 Subject: [PATCH 09/20] fix: assign remaining workers to one node --- grid-cli/cmd/deploy_kubernetes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index b547e305c..2fbc16521 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -190,7 +190,7 @@ var deployKubernetesCmd = &cobra.Command{ filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, - uint(len(workers)-len(workersNode)), + 1, ) workersNodes, err := deployer.FilterNodes( cmd.Context(), From 621807a3f68f0cfbef79b6f334b179602ac44cfe Mon Sep 17 00:00:00 2001 From: nabil salah Date: Wed, 31 Jul 2024 16:06:05 +0300 Subject: [PATCH 10/20] fix: assign unassigned worker to one node --- grid-cli/cmd/deploy_kubernetes.go | 2 -- grid-cli/internal/filters/filters.go | 21 ++++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 2fbc16521..7bce8f2b0 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -169,7 +169,6 @@ var deployKubernetesCmd = &cobra.Command{ filter, disks, rootfss := filters.BuildK8sFilter( master, masterFarm, - 1, ) nodes, err := deployer.FilterNodes( cmd.Context(), @@ -190,7 +189,6 @@ var deployKubernetesCmd = &cobra.Command{ filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, - 1, ) workersNodes, err := deployer.FilterNodes( cmd.Context(), diff --git a/grid-cli/internal/filters/filters.go b/grid-cli/internal/filters/filters.go index 2ee5ee683..85136f4bc 100644 --- a/grid-cli/internal/filters/filters.go +++ b/grid-cli/internal/filters/filters.go @@ -7,21 +7,16 @@ 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) - } - 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))) - } + disks := make([]uint64, 1) + rootfss := make([]uint64, 1) + disks = append(disks, *convertGBToBytes(uint64(k8sNode.DiskSize))) + // k8s rootfs is either 2 or 0.5 + rootfss = append(rootfss, *convertGBToBytes(uint64(2))) return buildGenericFilter(&freeMRUs, &freeSRUs, nil, &freeIPs, []uint64{farmID}, nil), disks, rootfss } From f48a222b3f91905f27103dd2762aa958a98968bf Mon Sep 17 00:00:00 2001 From: nabil salah Date: Wed, 31 Jul 2024 16:08:19 +0300 Subject: [PATCH 11/20] fix: assign unassigned worker to one node --- grid-cli/internal/filters/filters.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid-cli/internal/filters/filters.go b/grid-cli/internal/filters/filters.go index 85136f4bc..a00c98b16 100644 --- a/grid-cli/internal/filters/filters.go +++ b/grid-cli/internal/filters/filters.go @@ -9,7 +9,7 @@ import ( // BuildK8sFilter build a filter for a k8s node func BuildK8sFilter(k8sNode workloads.K8sNode, farmID uint64) (types.NodeFilter, []uint64, []uint64) { freeMRUs := uint64(k8sNode.Memory) / 1024 - freeSRUs := uint64(k8sNode.DiskSize ) + freeSRUs := uint64(k8sNode.DiskSize) freeIPs := uint64(0) disks := make([]uint64, 1) From 1e3a698ef0ceaea551c9b3597de6092ff2f58043 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Wed, 31 Jul 2024 16:33:45 +0300 Subject: [PATCH 12/20] fix: assign unassigned worker to one node --- grid-cli/cmd/deploy_kubernetes.go | 1 + 1 file changed, 1 insertion(+) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 7bce8f2b0..84b627614 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -197,6 +197,7 @@ var deployKubernetesCmd = &cobra.Command{ disks, nil, rootfss, + uint64(len(workers)-len(workersNode)), ) if err != nil { log.Fatal().Err(err).Send() From 372a5e9d23a90c7621e7caf1e33dcbf7b4b4138e Mon Sep 17 00:00:00 2001 From: nabil salah Date: Wed, 31 Jul 2024 17:04:45 +0300 Subject: [PATCH 13/20] fix: building filter to be on one node --- grid-cli/cmd/deploy_kubernetes.go | 6 +++--- grid-cli/internal/filters/filters.go | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 84b627614..5fb402694 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -185,7 +185,7 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if len(workersNode) < len(workers) && len(workers) > 0 { + if len(workersNode) < workerNumber && workerNumber > 0 { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, @@ -197,7 +197,7 @@ var deployKubernetesCmd = &cobra.Command{ disks, nil, rootfss, - uint64(len(workers)-len(workersNode)), + uint64(workerNumber-len(workersNode)), ) if err != nil { log.Fatal().Err(err).Send() @@ -206,7 +206,7 @@ var deployKubernetesCmd = &cobra.Command{ workersNode = append(workersNode, uint(workersNodes[i].NodeID)) } } - for i := 0; i < len(workers); i++ { + for i := 0; i < workerNumber; i++ { workers[i].Node = uint32(workersNode[i]) } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) diff --git a/grid-cli/internal/filters/filters.go b/grid-cli/internal/filters/filters.go index a00c98b16..7ac0f35cf 100644 --- a/grid-cli/internal/filters/filters.go +++ b/grid-cli/internal/filters/filters.go @@ -12,11 +12,12 @@ func BuildK8sFilter(k8sNode workloads.K8sNode, farmID uint64) (types.NodeFilter, freeSRUs := uint64(k8sNode.DiskSize) freeIPs := uint64(0) - disks := make([]uint64, 1) - rootfss := make([]uint64, 1) - disks = append(disks, *convertGBToBytes(uint64(k8sNode.DiskSize))) + if k8sNode.PublicIP { + freeIPs = uint64(1) + } + disks := []uint64{*convertGBToBytes(uint64(k8sNode.DiskSize))} // k8s rootfs is either 2 or 0.5 - rootfss = append(rootfss, *convertGBToBytes(uint64(2))) + rootfss := []uint64{*convertGBToBytes(uint64(2))} return buildGenericFilter(&freeMRUs, &freeSRUs, nil, &freeIPs, []uint64{farmID}, nil), disks, rootfss } From 834e204d1bb599f60459d80b57dea29a5535b03f Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 10:36:07 +0300 Subject: [PATCH 14/20] fix: renaming and initial value --- grid-cli/cmd/deploy_kubernetes.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 5fb402694..2274b6f1b 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -94,7 +94,7 @@ var deployKubernetesCmd = &cobra.Command{ return err } - workersNode, err := cmd.Flags().GetUintSlice("workers-node") + workersNodes, err := cmd.Flags().GetUintSlice("workers-node") if err != nil { return err } @@ -185,29 +185,29 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if len(workersNode) < workerNumber && workerNumber > 0 { + if len(workersNodes) < workerNumber && workerNumber > 0 { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, ) - workersNodes, err := deployer.FilterNodes( + nodes, err := deployer.FilterNodes( cmd.Context(), t, filter, disks, nil, rootfss, - uint64(workerNumber-len(workersNode)), + uint64(workerNumber-len(workersNodes)), ) if err != nil { log.Fatal().Err(err).Send() } - for i := 0; i < len(workersNodes); i++ { - workersNode = append(workersNode, uint(workersNodes[i].NodeID)) + for i := 0; i < len(nodes); i++ { + workersNodes = append(workersNodes, uint(nodes[i].NodeID)) } } for i := 0; i < workerNumber; i++ { - workers[i].Node = uint32(workersNode[i]) + workers[i].Node = uint32(workersNodes[i]) } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) if err != nil { @@ -279,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().UintSlice("workers-node", []uint{0}, "node id workers should be deployed on") + deployKubernetesCmd.Flags().UintSlice("workers-node", []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.Flags().Bool("workers-ipv4", false, "assign public ipv4 for workers") From aa6041ca3bd07d40edc78fa5bb94a5618a7f4082 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 11:03:42 +0300 Subject: [PATCH 15/20] fix: renaming and initial value --- grid-cli/cmd/deploy_kubernetes.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 2274b6f1b..bfc1cad01 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -94,7 +94,7 @@ var deployKubernetesCmd = &cobra.Command{ return err } - workersNodes, err := cmd.Flags().GetUintSlice("workers-node") + workersNodes, err := cmd.Flags().GetUintSlice("workers-nodes") if err != nil { return err } @@ -279,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().UintSlice("workers-node", []uint{}, "node id workers should be deployed on") + 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") From 88144237dd962a0fcee200325e95a30029c35cab Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 11:50:52 +0300 Subject: [PATCH 16/20] update: kubernetes docs and removed unreached condition --- grid-cli/cmd/deploy_kubernetes.go | 2 +- grid-cli/docs/kubernetes.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index bfc1cad01..e96174b9f 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -185,7 +185,7 @@ var deployKubernetesCmd = &cobra.Command{ masterNode = uint32(nodes[0].NodeID) } master.Node = masterNode - if len(workersNodes) < workerNumber && workerNumber > 0 { + if len(workersNodes) < workerNumber { filter, disks, rootfss := filters.BuildK8sFilter( workers[0], workersFarm, diff --git a/grid-cli/docs/kubernetes.md b/grid-cli/docs/kubernetes.md index 33805b8ad..802539d31 100644 --- a/grid-cli/docs/kubernetes.md +++ b/grid-cli/docs/kubernetes.md @@ -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). @@ -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 From c3bd4e11c36f7e9ef6dba55a73473653c08915d1 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 11:53:59 +0300 Subject: [PATCH 17/20] update: used range loops --- grid-cli/cmd/deploy_kubernetes.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index e96174b9f..a0f46e518 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -202,12 +202,12 @@ var deployKubernetesCmd = &cobra.Command{ if err != nil { log.Fatal().Err(err).Send() } - for i := 0; i < len(nodes); i++ { - workersNodes = append(workersNodes, uint(nodes[i].NodeID)) + for _,node := range nodes { + workersNodes = append(workersNodes, uint(node.NodeID)) } } - for i := 0; i < workerNumber; i++ { - workers[i].Node = uint32(workersNodes[i]) + for i, node := range workersNodes{ + workers[i].Node = uint32(node) } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) if err != nil { From 778c463a41f3c6fdac32c0781aba7b3c23d6fe3b Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 11:59:10 +0300 Subject: [PATCH 18/20] update: used range loops --- grid-cli/cmd/deploy_kubernetes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index a0f46e518..1b6875bfd 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -202,11 +202,11 @@ var deployKubernetesCmd = &cobra.Command{ if err != nil { log.Fatal().Err(err).Send() } - for _,node := range nodes { + for _, node := range nodes { workersNodes = append(workersNodes, uint(node.NodeID)) } } - for i, node := range workersNodes{ + for i, node := range workersNodes { workers[i].Node = uint32(node) } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) From 00fdba8281bfd537df1034b1239ff99bf8390db7 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 12:17:47 +0300 Subject: [PATCH 19/20] fix: wallet connector broken link in tfcmd readme --- grid-cli/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid-cli/README.md b/grid-cli/README.md index e269a13b7..e8114aaa9 100644 --- a/grid-cli/README.md +++ b/grid-cli/README.md @@ -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: From ddd1c77f90179b5d1dd004491214c12c6337ef68 Mon Sep 17 00:00:00 2001 From: nabil salah Date: Thu, 1 Aug 2024 13:52:55 +0300 Subject: [PATCH 20/20] fix: skipping extra given nodes --- grid-cli/cmd/deploy_kubernetes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grid-cli/cmd/deploy_kubernetes.go b/grid-cli/cmd/deploy_kubernetes.go index 1b6875bfd..dad851d67 100644 --- a/grid-cli/cmd/deploy_kubernetes.go +++ b/grid-cli/cmd/deploy_kubernetes.go @@ -206,8 +206,8 @@ var deployKubernetesCmd = &cobra.Command{ workersNodes = append(workersNodes, uint(node.NodeID)) } } - for i, node := range workersNodes { - workers[i].Node = uint32(node) + for i := range workers { + workers[i].Node = uint32(workersNodes[i]) } cluster, err := command.DeployKubernetesCluster(cmd.Context(), t, master, workers, string(sshKey)) if err != nil {