Skip to content

Commit

Permalink
feature. add params to importing cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Nov 29, 2022
1 parent 8ea9776 commit 6c385af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 14 additions & 4 deletions cmd/cluster-import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"errors"
"fmt"
"os"
"log"
"time"

Expand All @@ -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
Expand Down Expand Up @@ -65,24 +65,33 @@ tks cluster import <CLUSTERNAME> [--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,
}
jsonBytes, _ := m.Marshal(&data)
fmt.Println("Proto Json data: ")
fmt.Println(string(jsonBytes))
*/

r, err := client.ImportCluster(ctx, &data)
fmt.Println("Response:\n", r)
Expand All @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -44,3 +44,5 @@ require (
)

replace github.com/openinfradev/tks-client => ./

//replace github.com/openinfradev/tks-proto => ../tks-proto
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 6c385af

Please sign in to comment.