ISSUE-9100 POC on having better filter

Signed-off-by: Keith Lin <keithlin.732@gmail.com>
pull/9101/head
Keith Lin 5 years ago
parent 960fbbed70
commit 9aaeb2d6ba

@ -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.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.Failed, "failed", false, "show failed releases")
f.BoolVar(&client.Pending, "pending", false, "show pending 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.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.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") f.IntVar(&client.Offset, "offset", 0, "next release name in the list, used to offset from start value")

@ -17,6 +17,7 @@ limitations under the License.
package action package action
import ( import (
"os"
"path" "path"
"regexp" "regexp"
@ -126,6 +127,7 @@ type List struct {
Uninstalled bool Uninstalled bool
Superseded bool Superseded bool
Uninstalling bool Uninstalling bool
ServiceName string
Deployed bool Deployed bool
Failed bool Failed bool
Pending bool Pending bool
@ -154,7 +156,7 @@ func (l *List) Run() ([]*release.Release, error) {
return nil, err return nil, err
} }
} }
os.Setenv("helm-serviceName", l.ServiceName)
results, err := l.cfg.Releases.List(func(rel *release.Release) bool { results, err := l.cfg.Releases.List(func(rel *release.Release) bool {
// Skip anything that doesn't match the filter. // Skip anything that doesn't match the filter.
if filter != nil && !filter.MatchString(rel.Name) { if filter != nil && !filter.MatchString(rel.Name) {

@ -18,6 +18,7 @@ package driver // import "helm.sh/helm/v3/pkg/storage/driver"
import ( import (
"context" "context"
"os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -80,6 +81,12 @@ func (secrets *Secrets) Get(key string) (*rspb.Release, error) {
// secret fails to retrieve the releases. // secret fails to retrieve the releases.
func (secrets *Secrets) List(filter func(*rspb.Release) bool) ([]*rspb.Release, error) { func (secrets *Secrets) List(filter func(*rspb.Release) bool) ([]*rspb.Release, error) {
lsel := kblabels.Set{"owner": "helm"}.AsSelector() 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()} opts := metav1.ListOptions{LabelSelector: lsel.String()}
list, err := secrets.impl.List(context.Background(), opts) list, err := secrets.impl.List(context.Background(), opts)

Loading…
Cancel
Save