Skip to content

Commit

Permalink
add params to cluster_create cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
robertchoi80 committed Mar 19, 2022
1 parent 8b9590b commit 4a40526
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
53 changes: 33 additions & 20 deletions cmd/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CLUSTERNAME> --contract-id <CONTRACTID> --csp-id <CSPID>`,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -50,38 +50,46 @@ tks cluster create <CLUSTERNAME> --contract-id <CONTRACTID> --csp-id <CSPID>`,
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)
},
}
Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 4a40526

Please sign in to comment.