From 9aaeb2d6ba4efb6570a893ba390ade80aa47623f Mon Sep 17 00:00:00 2001 From: Keith Lin Date: Mon, 7 Dec 2020 21:25:47 -0800 Subject: [PATCH] ISSUE-9100 POC on having better filter Signed-off-by: Keith Lin --- cmd/helm/list.go | 1 + pkg/action/list.go | 4 +++- pkg/storage/driver/secrets.go | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/helm/list.go b/cmd/helm/list.go index b71278c7c..dc98cf17a 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -124,6 +124,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&client.Deployed, "deployed", false, "show deployed releases. If no other is specified, this will be automatically enabled") f.BoolVar(&client.Failed, "failed", false, "show failed releases") f.BoolVar(&client.Pending, "pending", false, "show pending releases") + f.StringVarP(&client.ServiceName, "servicename", "s", "", "Name of the helm deployment") f.BoolVarP(&client.AllNamespaces, "all-namespaces", "A", false, "list releases across all namespaces") f.IntVarP(&client.Limit, "max", "m", 256, "maximum number of releases to fetch") f.IntVar(&client.Offset, "offset", 0, "next release name in the list, used to offset from start value") diff --git a/pkg/action/list.go b/pkg/action/list.go index ebbc56b01..f50901b2c 100644 --- a/pkg/action/list.go +++ b/pkg/action/list.go @@ -17,6 +17,7 @@ limitations under the License. package action import ( + "os" "path" "regexp" @@ -126,6 +127,7 @@ type List struct { Uninstalled bool Superseded bool Uninstalling bool + ServiceName string Deployed bool Failed bool Pending bool @@ -154,7 +156,7 @@ func (l *List) Run() ([]*release.Release, error) { return nil, err } } - + os.Setenv("helm-serviceName", l.ServiceName) results, err := l.cfg.Releases.List(func(rel *release.Release) bool { // Skip anything that doesn't match the filter. if filter != nil && !filter.MatchString(rel.Name) { diff --git a/pkg/storage/driver/secrets.go b/pkg/storage/driver/secrets.go index 2e8530d0c..e4e605d75 100644 --- a/pkg/storage/driver/secrets.go +++ b/pkg/storage/driver/secrets.go @@ -18,6 +18,7 @@ package driver // import "helm.sh/helm/v3/pkg/storage/driver" import ( "context" + "os" "strconv" "strings" "time" @@ -80,6 +81,12 @@ func (secrets *Secrets) Get(key string) (*rspb.Release, error) { // secret fails to retrieve the releases. func (secrets *Secrets) List(filter func(*rspb.Release) bool) ([]*rspb.Release, error) { lsel := kblabels.Set{"owner": "helm"}.AsSelector() + if os.Getenv("helm-serviceName") != "" { + lsel = kblabels.Set{ + "owner": "helm", + "name": os.Getenv("helm-serviceName"), + }.AsSelector() + } opts := metav1.ListOptions{LabelSelector: lsel.String()} list, err := secrets.impl.List(context.Background(), opts)