Skip to content

Commit

Permalink
Allow using label selectors for system labels for secrets and configmap
Browse files Browse the repository at this point in the history
backends.

Fixes #12435

Signed-off-by: Dmitry Chepurovskiy <me@dm3ch.net>
  • Loading branch information
dm3ch committed Oct 3, 2023
1 parent c288f0b commit e219c75
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/driver/cfgmaps.go
Expand Up @@ -107,7 +107,7 @@ func (cfgmaps *ConfigMaps) List(filter func(*rspb.Release) bool) ([]*rspb.Releas
continue
}

rls.Labels = filterSystemLabels(item.ObjectMeta.Labels)
rls.Labels = item.ObjectMeta.Labels

if filter(rls) {
results = append(results, rls)
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/driver/cfgmaps_test.go
Expand Up @@ -128,6 +128,16 @@ func TestConfigMapList(t *testing.T) {
if len(ssd) != 2 {
t.Errorf("Expected 2 superseded, got %d", len(ssd))
}
// 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 TestConfigMapQuery(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/driver/secrets.go
Expand Up @@ -99,7 +99,7 @@ func (secrets *Secrets) List(filter func(*rspb.Release) bool) ([]*rspb.Release,
continue
}

rls.Labels = filterSystemLabels(item.ObjectMeta.Labels)
rls.Labels = item.ObjectMeta.Labels

if filter(rls) {
results = append(results, rls)
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/driver/secrets_test.go
Expand Up @@ -128,6 +128,16 @@ func TestSecretList(t *testing.T) {
if len(ssd) != 2 {
t.Errorf("Expected 2 superseded, got %d", len(ssd))
}
// 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 TestSecretQuery(t *testing.T) {
Expand Down

0 comments on commit e219c75

Please sign in to comment.