Allow using label selectors for system labels for sql backend.

Fixes #12435

Signed-off-by: Dmitry Chepurovskiy <me@dm3ch.net>
(cherry picked from commit e6d9b99255)
release-3.13
Dmitry Chepurovskiy 1 year ago committed by Matt Farina
parent 3b4cacf717
commit 10018ff34b

@ -19,6 +19,7 @@ package driver // import "helm.sh/helm/v3/pkg/storage/driver"
import (
"fmt"
"sort"
"strconv"
"time"
"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)
return nil, err
}
for k, v := range getReleaseSystemLabels(release) {
release.Labels[k] = v
}
if filter(release) {
releases = append(releases, release)
@ -681,3 +685,13 @@ func (s *SQL) getReleaseCustomLabels(key string, namespace string) (map[string]s
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 {
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) {

Loading…
Cancel
Save