diff --git a/pkg/storage/driver/cfgmaps.go b/pkg/storage/driver/cfgmaps.go index f05541d46..98bb9ffa4 100644 --- a/pkg/storage/driver/cfgmaps.go +++ b/pkg/storage/driver/cfgmaps.go @@ -244,6 +244,9 @@ func newConfigMapsObject(key string, rls *rspb.Release, lbs labels) (*v1.ConfigM lbs.init() } + // apply custom labels + lbs.fromMap(rls.Labels) + // apply labels lbs.set("name", rls.Name) lbs.set("owner", owner) diff --git a/pkg/storage/driver/mock_test.go b/pkg/storage/driver/mock_test.go index 1f96f04b1..7a1541a02 100644 --- a/pkg/storage/driver/mock_test.go +++ b/pkg/storage/driver/mock_test.go @@ -41,8 +41,8 @@ func releaseStub(name string, vers int, namespace string, status rspb.Status) *r Namespace: namespace, Info: &rspb.Info{Status: status}, Labels: map[string]string{ - "k1": "v1", - "k2": "v2", + "key1": "val1", + "key2": "val2", }, } } diff --git a/pkg/storage/driver/secrets.go b/pkg/storage/driver/secrets.go index e2be9548f..e714d2e80 100644 --- a/pkg/storage/driver/secrets.go +++ b/pkg/storage/driver/secrets.go @@ -226,6 +226,9 @@ func newSecretsObject(key string, rls *rspb.Release, lbs labels) (*v1.Secret, er lbs.init() } + // apply custom labels + lbs.fromMap(rls.Labels) + // apply labels lbs.set("name", rls.Name) lbs.set("owner", owner) diff --git a/pkg/storage/driver/sql.go b/pkg/storage/driver/sql.go index 58a360849..18f51f3fd 100644 --- a/pkg/storage/driver/sql.go +++ b/pkg/storage/driver/sql.go @@ -598,6 +598,11 @@ func (s *SQL) Delete(key string) (*rspb.Release, error) { return release, err } + if release.Labels, err = s.getReleaseCustomLabels(key, s.namespace); err != nil { + s.Log("failed to get release %s/%s custom labels: %v", s.namespace, key, err) + return nil, err + } + deleteCustomLabelsQuery, args, err := s.statementBuilder. Delete(sqlCustomLabelsTableName). Where(sq.Eq{sqlCustomLabelsTableReleaseKeyColumn: key}). diff --git a/pkg/storage/driver/sql_test.go b/pkg/storage/driver/sql_test.go index 1b0bdef86..2bbe05a9f 100644 --- a/pkg/storage/driver/sql_test.go +++ b/pkg/storage/driver/sql_test.go @@ -196,7 +196,7 @@ func TestSqlCreate(t *testing.T) { sqlCustomLabelsTableKeyColumn, sqlCustomLabelsTableValueColumn, ) - for k, v := range rel.Labels { + for k, v := range filterSystemLabels(rel.Labels) { mock. ExpectExec(regexp.QuoteMeta(labelsQuery)). WithArgs(key, rel.Namespace, k, v). @@ -478,6 +478,8 @@ func TestSqlDelete(t *testing.T) { WithArgs(key, namespace). WillReturnResult(sqlmock.NewResult(0, 1)) + mockGetReleaseCustomLabels(mock, key, namespace, rel.Labels) + deleteLabelsQuery := fmt.Sprintf( "DELETE FROM %s WHERE %s = $1 AND %s = $2", sqlCustomLabelsTableName, diff --git a/pkg/storage/driver/util_test.go b/pkg/storage/driver/util_test.go index 800049eca..5aa9f915b 100644 --- a/pkg/storage/driver/util_test.go +++ b/pkg/storage/driver/util_test.go @@ -34,8 +34,8 @@ func TestIsSystemLabel(t *testing.T) { func TestFilterSystemLabels(t *testing.T) { var tests = [][2]map[string]string{ - {nil, nil}, - {map[string]string{}, nil}, + {nil, map[string]string{}}, + {map[string]string{}, map[string]string{}}, {map[string]string{ "name": "name", "owner": "owner", @@ -43,7 +43,7 @@ func TestFilterSystemLabels(t *testing.T) { "version": "version", "createdAt": "createdAt", "modifiedAt": "modifiedAt", - }, nil}, + }, map[string]string{}}, {map[string]string{ "StaTus": "status", "name": "name",