-
Notifications
You must be signed in to change notification settings - Fork 30
CLOUDP-355710 Fix deletion of external roles #625
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
Conversation
MCK 1.6.1 Release NotesBug Fixes
|
| } | ||
|
|
||
| // Set annotation and state for previously configured roles | ||
| roleAnnotation, roleStrings, err := r.commonController.getRoleAnnotation(ctx, r.sc.Spec.DbCommonSpec, r.enableClusterMongoDBRoles, kube.ObjectKeyFromApiObject(r.sc)) |
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.
why do we rely on annotation where we have deployment state available? I understand this is necessary for mongodb and mdbmc as we don't have the state yet, but here?
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.
OK, I see that we actually rely on the LastConfiguredRoles in the logic, so the annotation is to align with other controllers?
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.
Yes. I can remove the annotation from the sharded cluster, I was unsure whether I should add it to both the state and the annotation
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 removed the annotation
| roles = mockOm.GetRoles() | ||
| require.Len(t, roles, 2) | ||
|
|
||
| // Delete embedded role, only the external should remain |
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.
q: why did the embedded role get removed?
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.
re-initialized rs to a replicaset without roles on line 573
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.
ahhhh "deleting" by re-initialisation. Can you update the comment to clarify that ?
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.
no, you're right, I'll just set the roles field to an empty array to make it clear
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.
done
| // This is achieved by removing currently configured roles from the deployed roles. | ||
| // To ensure that roles removed from the spec are also removed from OM, we also remove the previously configured roles. | ||
| // Finally, we add back the currently configured roles. | ||
| func mergeRoles(deployed []mdbv1.MongoDBRole, current []mdbv1.MongoDBRole, previous []string) []mdbv1.MongoDBRole { |
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.
blocking: lets add a dedicated unit test for mergeRoles
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.
done
| }}, | ||
| } | ||
| mockOm.AddRole(externalRole) | ||
|
|
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.
can you - for the sake of clarity - add here:
roles = mockOm.GetRoles()
require.Len(t, roles, 2)
as well?
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.
done
| --- | ||
| kind: fix | ||
| date: 2025-12-04 | ||
| --- | ||
|
|
||
| * Roles configured via Ops Manager UI or API will no longer be removed by the operator |
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.
LGTM!
Summary
This PR fixes an issue where roles added to an OM project outside the operator (through UI or the API) are overwritten by the operator every reconciliation. This is now consistent with the user behaviour, where users can be defined in the UI and will not be removed.
To accomplish this, we are now tracking the roles we configure with the operator in an annotation, and state configmap (where applicable). This was necessary due to possible usage of the
ClusterMongoDBRoleresource. If the reference to a role resource is removed at the same time as removing the resource itself, then it is not possible to determine which role needs to be removed from the automation config without knowing the previous set of roles.Proof of Work
Unit tests have been added to verify that the
ensureRolesmethod which is reused across all controllers behaves correctly. Additionally, the unit tests verify that each controller keeps track of the previously configured roles in an annotation.Checklist
skip-changeloglabel if not needed