Skip to content

Commit d6f12a3

Browse files
geekifierpcallewaert
authored andcommitted
feat: Support user-defined labels on secrets
1 parent e2c2169 commit d6f12a3

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ spec:
153153
privileges: OWNER # Can be OWNER/READ/WRITE
154154
annotations: # Annotations to be propagated to the secrets metadata section (optional)
155155
foo: "bar"
156+
labels:
157+
foo: "bar" # Labels to be propagated to the secrets metadata section (optional)
156158
secretTemplate: # Output secrets can be customized using standard Go templates
157159
PQ_URL: "host={{.Host}} user={{.Role}} password={{.Password}} dbname={{.Database}}"
158160
```

pkg/apis/db/v1alpha1/postgresuser_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ type PostgresUserSpec struct {
1919
Privileges string `json:"privileges"`
2020
// +optional
2121
Annotations map[string]string `json:"annotations,omitempty"`
22+
// +optional
23+
Labels map[string]string `json:"labels,omitempty"`
2224
}
2325

2426
// PostgresUserStatus defines the observed state of PostgresUser

pkg/controller/postgresuser/postgresuser_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ func (r *ReconcilePostgresUser) newSecretForCR(cr *dbv1alpha1.PostgresUser, role
286286
labels := map[string]string{
287287
"app": cr.Name,
288288
}
289+
// Merge in user-defined secret labels
290+
for k, v := range cr.Spec.Labels {
291+
labels[k] = v
292+
}
289293
annotations := cr.Spec.Annotations
290294
name := fmt.Sprintf("%s-%s", cr.Spec.SecretName, cr.Name)
291295
if r.keepSecretName {

0 commit comments

Comments
 (0)