Allow using label selectors for system labels for sql backend.

Fixes #12435

Signed-off-by: Dmitry Chepurovskiy <me@dm3ch.net>
pull/12447/head
Dmitry Chepurovskiy 1 year ago
parent e219c756e0
commit e6d9b99255
No known key found for this signature in database
GPG Key ID: 5B3A5FDCBFF9B3A4

@ -19,6 +19,7 @@ package driver // import "helm.sh/helm/v3/pkg/storage/driver"
import ( import (
"fmt" "fmt"
"sort" "sort"
"strconv"
"time" "time"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
@ -368,6 +369,9 @@ func (s *SQL) List(filter func(*rspb.Release) bool) ([]*rspb.Release, error) {
s.Log("failed to get release %s/%s custom labels: %v", record.Namespace, record.Key, err) s.Log("failed to get release %s/%s custom labels: %v", record.Namespace, record.Key, err)
return nil, err return nil, err
} }
for k, v := range getReleaseSystemLabels(release) {
release.Labels[k] = v
}
if filter(release) { if filter(release) {
releases = append(releases, release) releases = append(releases, release)
@ -681,3 +685,13 @@ func (s *SQL) getReleaseCustomLabels(key string, namespace string) (map[string]s
return filterSystemLabels(labelsMap), nil return filterSystemLabels(labelsMap), nil
} }
// Rebuild system labels from release object
func getReleaseSystemLabels(rls *rspb.Release) map[string]string {
return map[string]string{
"name": rls.Name,
"owner": sqlReleaseDefaultOwner,
"status": rls.Info.Status.String(),
"version": strconv.Itoa(rls.Version),
}
}

@ -157,6 +157,17 @@ func TestSQLList(t *testing.T) {
if err := mock.ExpectationsWereMet(); err != nil { if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("sql expectations weren't met: %v", err) t.Errorf("sql expectations weren't met: %v", err)
} }
// Check if release having both system and custom labels, this is needed to ensure that selector filtering would work.
rls := ssd[0]
_, ok := rls.Labels["name"]
if !ok {
t.Fatalf("Expected 'name' label in results, actual %v", rls.Labels)
}
_, ok = rls.Labels["key1"]
if !ok {
t.Fatalf("Expected 'key-1' label in results, actual %v", rls.Labels)
}
} }
func TestSqlCreate(t *testing.T) { func TestSqlCreate(t *testing.T) {

Loading…
Cancel
Save