From 6c385af555ca314c6bc3f030b640eca9fb749f9a Mon Sep 17 00:00:00 2001 From: Taekyu Date: Thu, 17 Nov 2022 10:37:50 +0900 Subject: [PATCH] feature. add params to importing cluster --- cmd/cluster-import.go | 18 ++++++++++++++---- go.mod | 4 +++- go.sum | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/cluster-import.go b/cmd/cluster-import.go index 216e2fd..c7be312 100644 --- a/cmd/cluster-import.go +++ b/cmd/cluster-import.go @@ -19,6 +19,7 @@ import ( "context" "errors" "fmt" + "os" "log" "time" @@ -28,7 +29,6 @@ import ( pb "github.com/openinfradev/tks-proto/tks_pb" "github.com/spf13/cobra" "github.com/spf13/viper" - "google.golang.org/protobuf/encoding/protojson" ) // clusterImportCmd represents the import command @@ -65,17 +65,25 @@ tks cluster import [--contract-id CONTRACTID --kubeconfig KUBECONF ContractId, _ := cmd.Flags().GetString("contract-id") creator, _ := cmd.Flags().GetString("creator") description, _ := cmd.Flags().GetString("description") - kubeconfig, _ := cmd.Flags().GetString("kubeconfig") + templateName, _ := cmd.Flags().GetString("template") + kubeconfigPath, _ := cmd.Flags().GetString("kubeconfig-path") + kubeconfig, err := os.ReadFile(kubeconfigPath) + if err != nil { + log.Fatalf("Failed to read kubeconfig from [%s] path", err) + log.Fatalf("Failed to read kubeconfig from [%s] path", kubeconfigPath) + } /* Construct request map */ data := pb.ImportClusterRequest{ Name: ClusterName, ContractId: ContractId, Kubeconfig: kubeconfig, + TemplateName: templateName, Creator: creator, Description: description, } + /* Comment for security m := protojson.MarshalOptions{ Indent: " ", UseProtoNames: true, @@ -83,6 +91,7 @@ tks cluster import [--contract-id CONTRACTID --kubeconfig KUBECONF jsonBytes, _ := m.Marshal(&data) fmt.Println("Proto Json data: ") fmt.Println(string(jsonBytes)) + */ r, err := client.ImportCluster(ctx, &data) fmt.Println("Response:\n", r) @@ -109,8 +118,9 @@ func init() { // is called directly, e.g.: // clusterCreateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") clusterImportCmd.Flags().String("contract-id", "", "Contract ID") - _ = clusterImportCmd.MarkFlagRequired("contract-id") - clusterImportCmd.Flags().String("kubeconfig", "", "Kubeconfig of the cluster") + clusterImportCmd.Flags().String("kubeconfig-path", "", "Path of Kubeconfig for importing cluster") + _ = clusterImportCmd.MarkFlagRequired("kubeconfig-path") + clusterImportCmd.Flags().String("template", "aws-reference", "Template name for the cluster") clusterImportCmd.Flags().String("creator", "", "Uuid of creator") clusterImportCmd.Flags().String("description", "", "Description of cluster") diff --git a/go.mod b/go.mod index 0094924..99b0e15 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.19 require ( github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/matryer/is v1.4.0 + github.com/openinfradev/tks-proto v0.0.6-0.20221117013032-f3e8aa863671 github.com/spf13/cobra v1.5.0 github.com/spf13/viper v1.13.0 google.golang.org/grpc v1.49.0 @@ -23,7 +24,6 @@ require ( github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/oklog/ulid v1.3.1 // indirect - github.com/openinfradev/tks-proto v0.0.6-0.20221108083743-52cfd2c1ce73 // indirect github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/rivo/uniseg v0.4.2 // indirect @@ -44,3 +44,5 @@ require ( ) replace github.com/openinfradev/tks-client => ./ + +//replace github.com/openinfradev/tks-proto => ../tks-proto diff --git a/go.sum b/go.sum index 372620e..57ac3da 100644 --- a/go.sum +++ b/go.sum @@ -177,8 +177,8 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/openinfradev/tks-proto v0.0.6-0.20221108083743-52cfd2c1ce73 h1:IEy2rxUKHVBmkv9/UZk+2Rh6I9B2DaoabndkqtEF8Y8= -github.com/openinfradev/tks-proto v0.0.6-0.20221108083743-52cfd2c1ce73/go.mod h1:IIxiwEZVfqLXm/O4KGiD0q/ELlyKxXx44TCM5ZWhpJs= +github.com/openinfradev/tks-proto v0.0.6-0.20221117013032-f3e8aa863671 h1:zcGUqoU2N0tE+G2aZTZE63dX2xT72mos7amCJiAk1s8= +github.com/openinfradev/tks-proto v0.0.6-0.20221117013032-f3e8aa863671/go.mod h1:IIxiwEZVfqLXm/O4KGiD0q/ELlyKxXx44TCM5ZWhpJs= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=