Skip to content

Commit

Permalink
Applied suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-karpukhin committed Jan 8, 2025
1 parent 67965bd commit 358d4b8
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions internal/controller/atlasproject/custom_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,15 @@ func getLastAppliedCustomRoles(atlasProject *akov2.AtlasProject) ([]akov2.Custom

func findRolesToDelete(prevSpec, akoRoles, atlasRoles []customroles.CustomRole) map[string]customroles.CustomRole {
result := map[string]customroles.CustomRole{}
deletionCandidates := map[string]customroles.CustomRole{}
lastAppliedRolesMap := mapCustomRolesByName(prevSpec)
akoRolesMap := mapCustomRolesByName(akoRoles)
atlasRolesMap := mapCustomRolesByName(atlasRoles)

// Get roles from the previous spec
for _, customRole := range prevSpec {
deletionCandidates[customRole.Name] = customRole
}
// Get roles from the current spec and remove the ones that are in the previous spec
for _, customRole := range akoRoles {
delete(deletionCandidates, customRole.Name)
}

// Compare combinedAkoRoles with the current Atlas roles
for _, role := range deletionCandidates {
if _, exists := atlasRolesMap[role.Name]; exists {
result[role.Name] = role

for atlasIx, atlasRole := range atlasRolesMap {
_, inAKO := akoRolesMap[atlasIx]
_, inLastApplied := lastAppliedRolesMap[atlasIx]
if !inAKO && inLastApplied {
result[atlasIx] = atlasRole
}
}

Expand Down

0 comments on commit 358d4b8

Please sign in to comment.