From 4a40526d19140823f8e18d045283c8fc182fcdea Mon Sep 17 00:00:00 2001 From: Robert Choi Date: Tue, 15 Mar 2022 15:43:45 +0900 Subject: [PATCH] add params to cluster_create cmd --- cmd/cluster_create.go | 53 +++++++++++++++++++++++++++---------------- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/cmd/cluster_create.go b/cmd/cluster_create.go index b5623f3..9dc4f00 100644 --- a/cmd/cluster_create.go +++ b/cmd/cluster_create.go @@ -38,7 +38,7 @@ var clusterCreateCmd = &cobra.Command{ Use: "create", Short: "Create a TACO Cluster.", Long: `Create a TACO Cluster to AWS. - + Example: tks cluster create --contract-id --csp-id `, Run: func(cmd *cobra.Command, args []string) { @@ -50,38 +50,46 @@ tks cluster create --contract-id --csp-id `, var conn *grpc.ClientConn conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { - log.Fatalf("did not connect: %s", err) + log.Fatalf("Could not connect to LCM server: %s", err) } defer conn.Close() client := pb.NewClusterLcmServiceClient(conn) - ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) defer cancel() - data := make([]pb.CreateClusterRequest, 1) - conf := &pb.ClusterConf{} + + /* Parse command line arguments */ + ClusterName := args[0] ContractId, _ := cmd.Flags().GetString("contract-id") CspId, _ := cmd.Flags().GetString("csp-id") - ClusterName := args[0] - data[0].ContractId = ContractId - data[0].CspId = CspId - data[0].Name = ClusterName - conf.MasterFlavor = "hello" - conf.MasterReplicas = 10 - conf.MasterRootSize = 50 - conf.WorkerFlavor = "hello" - conf.WorkerRootSize = 50 - conf.WorkerReplicas = 10 - conf.K8SVersion = "Hello" - data[0].Conf = conf + + conf := pb.ClusterRawConf{} + conf.SshKeyName, _ = cmd.Flags().GetString("ssh-key-name") + conf.Region, _ = cmd.Flags().GetString("region") + conf.MachineType, _ = cmd.Flags().GetString("machine-type") + + numOfAz, _ := cmd.Flags().GetInt("num-of-az") + conf.NumOfAz = int32(numOfAz) + + machineReplicas, _ := cmd.Flags().GetInt("machine-replicas") + conf.MachineReplicas = int32(machineReplicas) + + /* Construct request map */ + data := pb.CreateClusterRequest{ + Name: ClusterName, + ContractId: ContractId, + CspId: CspId, + Conf: &conf, + } m := protojson.MarshalOptions{ Indent: " ", UseProtoNames: true, } - jsonBytes, _ := m.Marshal(&data[0]) - fmt.Println("Proto Json data...") + jsonBytes, _ := m.Marshal(&data) + fmt.Println("Proto Json data: ") fmt.Println(string(jsonBytes)) - r, err := client.CreateCluster(ctx, &data[0]) + r, err := client.CreateCluster(ctx, &data) fmt.Println(r) }, } @@ -102,4 +110,9 @@ func init() { clusterCreateCmd.MarkFlagRequired("contract-id") clusterCreateCmd.Flags().String("csp-id", "", "CSP ID") clusterCreateCmd.MarkFlagRequired("csp-id") + clusterCreateCmd.Flags().String("region", "", "AWS Region") + clusterCreateCmd.Flags().Int("num-of-az", 3, "Number of availability zones in selected region") + clusterCreateCmd.Flags().String("ssh-key-name", "", "SSH key name for EC2 instance connection") + clusterCreateCmd.Flags().String("machine-type", "", "machine type of worker node") + clusterCreateCmd.Flags().Int("machine-replicas", 3, "machine replicas of worker node") } diff --git a/go.mod b/go.mod index b8eeff3..c659ffa 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/kr/text v0.2.0 // indirect github.com/matryer/is v1.4.0 github.com/openinfradev/tks-contract v0.1.1-0.20210928021110-fe2b666327cc - github.com/openinfradev/tks-proto v0.0.6-0.20211015003551-ed8f9541f40d + github.com/openinfradev/tks-proto v0.0.6-0.20220318062944-7fccd257bcae github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.7.0 diff --git a/go.sum b/go.sum index e655226..ee36536 100644 --- a/go.sum +++ b/go.sum @@ -421,6 +421,8 @@ github.com/openinfradev/tks-contract v0.1.1-0.20210928021110-fe2b666327cc/go.mod github.com/openinfradev/tks-proto v0.0.6-0.20210924020717-178698d59e9d/go.mod h1:WDzIQ7ayHVA7cA3Z+D2etK7gQuo4penewcC/cWcewlA= github.com/openinfradev/tks-proto v0.0.6-0.20211015003551-ed8f9541f40d h1:ypM1LN+7tjRGzmTBNVegY/25KhJLFuQor2/+DfuhxDM= github.com/openinfradev/tks-proto v0.0.6-0.20211015003551-ed8f9541f40d/go.mod h1:ul6kvgOXhNQvXEUmb92Wh5BmsuzknnTCb3wqmVNd/iI= +github.com/openinfradev/tks-proto v0.0.6-0.20220318062944-7fccd257bcae h1:n4VlqbtNhQ36WMrqHCWkHp7PR5qUr3AVDdOBINZoa5o= +github.com/openinfradev/tks-proto v0.0.6-0.20220318062944-7fccd257bcae/go.mod h1:3DrATRNCUJMW0oMLHT6D1teN4hX0vMGH4qOGnadakmo= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=