From d485a2d3c39876af5182f0b94696830b24146264 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Mon, 28 Mar 2022 14:48:13 +0900 Subject: [PATCH] feature. add filter to cluster list --- cmd/cluster_list.go | 15 +++++++++++++-- go.mod | 3 +-- go.sum | 6 ++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/cluster_list.go b/cmd/cluster_list.go index e5c62e0..b211169 100644 --- a/cmd/cluster_list.go +++ b/cmd/cluster_list.go @@ -74,7 +74,7 @@ tks cluster list (--long)`, if err != nil { fmt.Println(err) } else { - printClusters(r, long) + printClusters(filterResponse(r), long) } }, } @@ -94,7 +94,6 @@ func init() { } func printClusters(r *pb.GetClustersResponse, long bool) { - fmt.Println(r.Clusters[0].Name) t := table.NewWriter() tTemp := table.Table{} tTemp.Render() @@ -126,3 +125,15 @@ func parseTime(t *timestamppb.Timestamp) string { return t.AsTime().Format("2006-01-02 15:04:05") } + +func filterResponse(r *pb.GetClustersResponse) *pb.GetClustersResponse { + clusters := []*pb.Cluster {} + for _, cluster := range r.Clusters { + if cluster.GetStatus() != pb.ClusterStatus_DELETED { + clusters = append(clusters, cluster) + } + } + + r.Clusters = clusters + return r +} diff --git a/go.mod b/go.mod index 533296d..170e2ed 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,9 @@ require ( github.com/jedib0t/go-pretty v4.3.0+incompatible 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.20220318062944-7fccd257bcae + github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49 github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.9.0 - github.com/stretchr/testify v1.7.0 // indirect golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect golang.org/x/sys v0.0.0-20211023085530-d6a326fbbf70 // indirect google.golang.org/genproto v0.0.0-20211021150943-2b146023228c // indirect diff --git a/go.sum b/go.sum index 6b31e65..ba20764 100644 --- a/go.sum +++ b/go.sum @@ -438,10 +438,8 @@ github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWEr github.com/openinfradev/tks-contract v0.1.1-0.20210928021110-fe2b666327cc h1:CwlJuBCGJqCA11SVEk/Qdtp5n1KRJPZweXESd+C/NQ0= github.com/openinfradev/tks-contract v0.1.1-0.20210928021110-fe2b666327cc/go.mod h1:Fs/fid/nEajtBWS068Vi0IDKFbBSiL4OWu9L1J124Rc= 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/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49 h1:XYNl9fXGUH02/Laqht+ba2FmgOXrl7sUDHcAZHsSaUE= +github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49/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=