Skip to content

Commit

Permalink
Add cmd for deleting cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaesang committed Mar 15, 2022
1 parent 8b9590b commit 2a9ee7d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
77 changes: 77 additions & 0 deletions cmd/cluster_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright © 2022 SK Telecom <https://github.com/openinfradev>
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 <CLUSTER_ID>`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("You must specify cluster name.")
fmt.Println("Usage: tks cluster delete <CLUSTER_ID>")
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)
}
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.20220304011855-99ac351f420f
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.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=
Expand Down

0 comments on commit 2a9ee7d

Please sign in to comment.