From 2a9ee7dbff2b44598ba3a33b542455fb6bf3d86b Mon Sep 17 00:00:00 2001 From: Jaesang Lee Date: Tue, 15 Mar 2022 06:33:43 +0000 Subject: [PATCH] Add cmd for deleting cluster --- cmd/cluster_delete.go | 77 +++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 cmd/cluster_delete.go diff --git a/cmd/cluster_delete.go b/cmd/cluster_delete.go new file mode 100644 index 0000000..5a77b6b --- /dev/null +++ b/cmd/cluster_delete.go @@ -0,0 +1,77 @@ +/* +Copyright © 2022 SK Telecom + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "context" + "fmt" + "log" + "os" + "time" + + "google.golang.org/grpc" + + pb "github.com/openinfradev/tks-proto/tks_pb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" +) + +// clusterDeleteCmd represents the delete command +var clusterDeleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete a TACO Cluster.", + Long: `Delete a TACO Cluster to AWS. + +Example: +tks cluster delete `, + Run: func(cmd *cobra.Command, args []string) { + if len(args) == 0 { + fmt.Println("You must specify cluster name.") + fmt.Println("Usage: tks cluster delete ") + os.Exit(1) + } + var conn *grpc.ClientConn + conn, err := grpc.Dial(address, grpc.WithInsecure()) + if err != nil { + log.Fatalf("did not connect: %s", err) + } + defer conn.Close() + + client := pb.NewClusterLcmServiceClient(conn) + ctx, cancel := context.WithTimeout(context.Background(), 30 * time.Minute) + defer cancel() + data := make([]pb.IDRequest, 1) + data[0].Id = args[0] + m := protojson.MarshalOptions{ + Indent: " ", + UseProtoNames: true, + } + jsonBytes, _ := m.Marshal(&data[0]) + fmt.Println("Proto Json data...") + fmt.Println(string(jsonBytes)) + r, err := client.DeleteCluster(ctx, &data[0]) + fmt.Println(r) + if err != nil { + fmt.Println(err) + } else { + fmt.Println("The request to delete cluster ", args[0], " was accepted.") + } + }, +} + +func init() { + clusterCmd.AddCommand(clusterDeleteCmd) +} diff --git a/go.mod b/go.mod index b8eeff3..1d8d828 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.20220304011855-99ac351f420f 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..9a8c2ed 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.20220304011855-99ac351f420f h1:B6pnfHoNabwG1MhX1iwjP7lCS7z2nRT/mf/elv8weXI= +github.com/openinfradev/tks-proto v0.0.6-0.20220304011855-99ac351f420f/go.mod h1:ul6kvgOXhNQvXEUmb92Wh5BmsuzknnTCb3wqmVNd/iI= 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=