From afb9ce6a10a093bc5daffb2505d8973aad70bff2 Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Wed, 8 May 2019 23:18:08 +0200 Subject: [PATCH] add params required for sort byNamespace Signed-off-by: Abhilash Gnan --- _proto/hapi/services/tiller.proto | 1 + cmd/helm/list.go | 5 +++++ pkg/releaseutil/sorter.go | 12 ++++++++++++ pkg/tiller/release_list.go | 2 ++ 4 files changed, 20 insertions(+) diff --git a/_proto/hapi/services/tiller.proto b/_proto/hapi/services/tiller.proto index 1d0cc7ec6..46e55043f 100644 --- a/_proto/hapi/services/tiller.proto +++ b/_proto/hapi/services/tiller.proto @@ -125,6 +125,7 @@ message ListSort{ NAME = 1; LAST_RELEASED = 2; CHART_NAME = 3; + NAMESPACE = 4; } // SortOrder defines sort orders to augment sorting operations. diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 3ca3fbbfa..b06d92d59 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -79,6 +79,7 @@ type listCmd struct { colWidth uint output string byChartName bool + byNamespace bool } type listResult struct { @@ -136,6 +137,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { f.UintVar(&list.colWidth, "col-width", 60, "specifies the max column width of output") f.StringVar(&list.output, "output", "", "output the specified format (json or yaml)") f.BoolVarP(&list.byChartName, "chart-name", "c", false, "sort by chart name") + f.BoolVarP(&list.byNamespace, "namespace-name", "n", false, "sort by namespace name") // TODO: Do we want this as a feature of 'helm list'? //f.BoolVar(&list.superseded, "history", true, "show historical releases") @@ -154,6 +156,9 @@ func (l *listCmd) run() error { if l.byChartName { sortBy = services.ListSort_CHART_NAME } + if l.byNamespace { + sortBy = services.ListSort_NAMESPACE + } sortOrder := services.ListSort_ASC if l.sortDesc { diff --git a/pkg/releaseutil/sorter.go b/pkg/releaseutil/sorter.go index 977f49398..5f77e3876 100644 --- a/pkg/releaseutil/sorter.go +++ b/pkg/releaseutil/sorter.go @@ -98,3 +98,15 @@ func SortByChartName(list []*rspb.Release) { } sort.Sort(s) } + +// SortByNamespace sorts the list of releases by a +// release's namespace name in lexicographical order. +func SortByNamespace(list []*rspb.Release) { + s := &sorter{list: list} + s.less = func(i, j int) bool { + ni := s.list[i].Namespace + nj := s.list[j].Namespace + return ni < nj + } + sort.Sort(s) +} diff --git a/pkg/tiller/release_list.go b/pkg/tiller/release_list.go index 6d62c7bc4..26d50133e 100644 --- a/pkg/tiller/release_list.go +++ b/pkg/tiller/release_list.go @@ -68,6 +68,8 @@ func (s *ReleaseServer) ListReleases(req *services.ListReleasesRequest, stream s relutil.SortByDate(rels) case services.ListSort_CHART_NAME: relutil.SortByChartName(rels) + case services.ListSort_NAMESPACE: + relutil.SortByNamespace(rels) } if req.SortOrder == services.ListSort_DESC {