Skip to content

Commit 63ea089

Browse files
committed
feat: add feature flag for password update when user reconciles
1 parent 3a1acbc commit 63ea089

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

api/v1beta1/user_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type UserSpec struct {
3737
//
3838
// Note that this import only occurs at creation time, and is ignored once a password has been set on a User.
3939
ImportCredentialsSecret *corev1.LocalObjectReference `json:"importCredentialsSecret,omitempty"`
40+
// Feature flag to always regenerate the `-user-credentials` Secret from the ImportCredentialsSecret.
41+
// Defaults to false if omitted.
42+
// +kubebuilder:validation:Optional
43+
AutoUpdateCredentialsSecret bool `json:"autoUpdateCredentialsSecret,omitempty"`
4044
}
4145

4246
// UserStatus defines the observed state of User.

config/crd/bases/rabbitmq.com_users.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ spec:
4141
spec:
4242
description: Spec configures the desired state of the User object.
4343
properties:
44+
autoUpdateCredentialsSecret:
45+
description: |-
46+
Feature flag to always regenerate the `-user-credentials` Secret from the ImportCredentialsSecret.
47+
Defaults to false if omitted.
48+
type: boolean
4449
importCredentialsSecret:
4550
description: |-
4651
Defines a Secret containing the credentials for the User. If this field is omitted, random a username and

controllers/user_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (r *UserReconciler) declareCredentials(ctx context.Context, user *topology.
9898
for i := range credentialSecret.ObjectMeta.OwnerReferences {
9999
credentialSecret.ObjectMeta.OwnerReferences[i].BlockOwnerDeletion = ptr.To(false)
100100
}
101+
credentialSecret.Data = credentialSecretData
101102
return nil
102103
})
103104
return apiError
@@ -190,15 +191,15 @@ func (r *UserReconciler) DeclareFunc(ctx context.Context, client rabbitmqclient.
190191
user := obj.(*topology.User)
191192
if user.Status.Credentials == nil || user.Status.Username == "" {
192193
var username string
193-
if user.Status.Credentials != nil && user.Status.Username == "" {
194+
if user.Status.Credentials != nil && user.Status.Username == "" || user.Spec.AutoUpdateCredentialsSecret {
194195
// Only run once for migration to set user.Status.Username on existing resources
195196
credentials, err := r.getUserCredentials(ctx, user)
196197
if err != nil {
197198
return err
198199
}
199200
username = string(credentials.Data["username"])
200201
} else {
201-
logger.Info("User does not yet have a Credentials Secret; generating", "user", user.Name)
202+
logger.Info("User does not yet have a Credentials Secret or AutoUpdateCredentialsSecret is enabled; generating Credentials Secret", "user", user.Name)
202203
var err error
203204
if username, err = r.declareCredentials(ctx, user); err != nil {
204205
return err

docs/api/rabbitmq.com.ref.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,8 @@ password will be generated. The Secret must have the following keys in its Data
14221422

14231423

14241424
Note that this import only occurs at creation time, and is ignored once a password has been set on a User.
1425+
| *`autoUpdateCredentialsSecret`* __boolean__ | Feature flag to always regenerate the `-user-credentials` Secret from the ImportCredentialsSecret.
1426+
Defaults to false if omitted.
14251427
|===
14261428

14271429

0 commit comments

Comments
 (0)