Added selector filtering

Signed-off-by: Dmitry Chepurovskiy <dm3ch@dm3ch.net>
pull/8532/head
Dmitry Chepurovskiy 4 years ago
parent 99bd709530
commit 357a0785bc
No known key found for this signature in database
GPG Key ID: A9B6ED8F3D834514

@ -20,6 +20,8 @@ import (
"path" "path"
"regexp" "regexp"
"k8s.io/apimachinery/pkg/labels"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/releaseutil" "helm.sh/helm/v3/pkg/releaseutil"
) )
@ -152,11 +154,22 @@ func (l *List) Run() ([]*release.Release, error) {
} }
} }
selectorObj, err := labels.Parse(l.Selector)
if err != nil {
return nil, err
}
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) {
return false return false
} }
// Skip anything that doesn't match the selector
if ! selectorObj.Matches(labels.Set(rel.Labels)) {
return false
}
return true return true
}) })

@ -105,8 +105,10 @@ func (cfgmaps *ConfigMaps) List(filter func(*rspb.Release) bool) ([]*rspb.Releas
cfgmaps.Log("list: failed to decode release: %v: %s", item, err) cfgmaps.Log("list: failed to decode release: %v: %s", item, err)
continue continue
} }
if filter(rls) {
rls.Labels = item.ObjectMeta.Labels rls.Labels = item.ObjectMeta.Labels
if filter(rls) {
results = append(results, rls) results = append(results, rls)
} }
} }

@ -97,8 +97,10 @@ func (secrets *Secrets) List(filter func(*rspb.Release) bool) ([]*rspb.Release,
secrets.Log("list: failed to decode release: %v: %s", item, err) secrets.Log("list: failed to decode release: %v: %s", item, err)
continue continue
} }
if filter(rls) {
rls.Labels = item.ObjectMeta.Labels rls.Labels = item.ObjectMeta.Labels
if filter(rls) {
results = append(results, rls) results = append(results, rls)
} }
} }

Loading…
Cancel
Save