-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extraction of creation and deletion logic of Cassandra User from controller predicates #616
Extraction of creation and deletion logic of Cassandra User from controller predicates #616
Conversation
97a6741
to
60a82b9
Compare
addedRefs, deletedRefs := cassandra.Status.AvailableUsers.Diff(cassandra.Spec.UserRefs) | ||
|
||
for _, ref := range addedRefs { | ||
err = r.handleUsersCreate(ctx, l, cassandra, ref) | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
} | ||
|
||
for _, ref := range deletedRefs { | ||
err = r.handleUsersDelete(ctx, l, cassandra, ref) | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
} | ||
|
||
if addedRefs != nil || deletedRefs != nil { | ||
cassandra.Status.AvailableUsers = cassandra.Spec.UserRefs | ||
err = r.Status().Patch(ctx, cassandra, patch) | ||
if err != nil { | ||
l.Error(err, "Failed to patch cluster status with created user") | ||
r.EventRecorder.Eventf(cassandra, models.Warning, models.CreationFailed, | ||
"Failed to create a user for the cluster. Reason: %v", err) | ||
|
||
return reconcile.Result{}, err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible please make it generic and call it handleUserChanges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented the following flow as a generic by using interfaces. Also, I've implemented a generic func for detaching users from the cluster.
e15e84b
to
8191a3a
Compare
…cassandra controller predicates
8191a3a
to
5de755e
Compare
Our previous implementation of the creation and deletion of users for the
Cassandra
resource manages to do it in predicates. Implementing the CRUD inside theReconcile
func is natural and convenient.It also allows controllers to re-run reconciliation if there is any error during the creation or deletion of the user, which it is not reachable when it uses predicates.
The PR extracts
CassandraUser
CRUD functions out ofCassandraController
predicates.(upd. 13.11) Added a generic solution for handling user changes for all user resources.
(upd. 14.11) Enhanced approach to handling user changes; added generic detaching users func