Skip to content
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

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

worryg0d
Copy link
Collaborator

@worryg0d worryg0d commented Nov 8, 2023

Our previous implementation of the creation and deletion of users for the Cassandra resource manages to do it in predicates. Implementing the CRUD inside the Reconcile 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 of CassandraController 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

@worryg0d worryg0d added the enhancement New feature or request label Nov 8, 2023
@worryg0d worryg0d self-assigned this Nov 8, 2023
@worryg0d worryg0d marked this pull request as draft November 8, 2023 12:57
@worryg0d worryg0d force-pushed the issue-607-moving-user-crud-out-of-predicates branch 5 times, most recently from 97a6741 to 60a82b9 Compare November 9, 2023 14:24
@worryg0d worryg0d changed the title [WIP] Cassandra User CRUD [WIP] Cassandra User extraction of creation and deletion logic from controller predicates Nov 9, 2023
@worryg0d worryg0d changed the title [WIP] Cassandra User extraction of creation and deletion logic from controller predicates Extraction of creation and deletion logic of Cassandra User from controller predicates Nov 9, 2023
@worryg0d worryg0d marked this pull request as ready for review November 9, 2023 14:25
Comment on lines 388 to 395
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
}
}
Copy link
Contributor

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

Copy link
Collaborator Author

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.

@worryg0d worryg0d force-pushed the issue-607-moving-user-crud-out-of-predicates branch from e15e84b to 8191a3a Compare November 14, 2023 12:31
@worryg0d worryg0d force-pushed the issue-607-moving-user-crud-out-of-predicates branch from 8191a3a to 5de755e Compare November 14, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants