@@ -203,90 +203,7 @@ func (r *PostgresUserReconciler) Reconcile(ctx context.Context, req ctrl.Request
203203 }
204204 } else if awsIamRequested {
205205 reqLogger .WithValues ("role" , role ).Info ("IAM Auth requested while we are not running with AWS cloud provider config" )
206- // Reconcile logic for changes in group membership
207- // This is only applicable if user role is already created
208- // and privileges are changed in spec
209- if instance .Status .PostgresRole != "" {
210-
211- // We need to get the Postgres CR to get the group role name
212- database , err := r .getPostgresCR (ctx , instance )
213- if err != nil {
214- return r .requeue (ctx , instance , errors .NewInternalError (err ))
215- }
216-
217- // Determine desired group role
218- var desiredGroup string
219- switch instance .Spec .Privileges {
220- case "READ" :
221- desiredGroup = database .Status .Roles .Reader
222- case "WRITE" :
223- desiredGroup = database .Status .Roles .Writer
224- default :
225- desiredGroup = database .Status .Roles .Owner
226- }
227-
228- // Ability user to be reassigned to another group role
229- currentGroup := instance .Status .PostgresGroup
230- if desiredGroup != "" && currentGroup != desiredGroup {
231-
232- // Remove the old group membership if present
233- if currentGroup != "" {
234- err = r .pg .RevokeRole (currentGroup , role )
235- if err != nil {
236- return r .requeue (ctx , instance , errors .NewInternalError (err ))
237- }
238- }
239-
240- // Grant the new group role
241- err = r .pg .GrantRole (desiredGroup , role )
242- if err != nil {
243- return r .requeue (ctx , instance , errors .NewInternalError (err ))
244- }
245-
246- // Ensure objects created by the user are owned by the new group
247- err = r .pg .AlterDefaultLoginRole (role , desiredGroup )
248- if err != nil {
249- return r .requeue (ctx , instance , errors .NewInternalError (err ))
250- }
251-
252- instance .Status .PostgresGroup = desiredGroup
253- err = r .Status ().Update (ctx , instance )
254- if err != nil {
255- return r .requeue (ctx , instance , err )
256- }
257- }
258- } else {
259- role = instance .Status .PostgresRole
260- login = instance .Status .PostgresLogin
261-
262- awsConfig := instance .Spec .AWS
263- awsIamRequested := awsConfig != nil && awsConfig .EnableIamAuth
264-
265- if r .cloudProvider == "AWS" {
266- if awsIamRequested && ! instance .Status .EnableIamAuth {
267- if err := r .pg .GrantRole ("rds_iam" , role ); err != nil {
268- reqLogger .WithValues ("role" , role ).Error (err , "failed to grant rds_iam role" )
269- } else {
270- instance .Status .EnableIamAuth = true
271- if sErr := r .Status ().Update (ctx , instance ); sErr != nil {
272- reqLogger .WithValues ("role" , role ).Error (sErr , "failed to update status after IAM grant" )
273- }
274- }
275- }
276-
277- // Revoke aws_iam role on transition: spec=false, status=true
278- if ! awsIamRequested && instance .Status .EnableIamAuth {
279- if err := r .pg .RevokeRole ("rds_iam" , role ); err != nil {
280- reqLogger .WithValues ("role" , role ).Error (err , "failed to revoke rds_iam role" )
281- } else {
282- instance .Status .EnableIamAuth = false
283- if sErr := r .Status ().Update (ctx , instance ); sErr != nil {
284- reqLogger .WithValues ("role" , role ).Error (sErr , "failed to update status after IAM revoke" )
285- }
286- }
287- }
288- } else if awsIamRequested {
289- reqLogger .WithValues ("role" , role ).Info ("IAM Auth requested while we are not running with AWS cloud provider config" )
206+ }
290207
291208 // Reconcile logic for changes in group membership
292209 // This is only applicable if user role is already created
@@ -315,27 +232,23 @@ func (r *PostgresUserReconciler) Reconcile(ctx context.Context, req ctrl.Request
315232
316233 // Remove the old group membership if present
317234 if currentGroup != "" {
318- err = r .pg .RevokeRole (currentGroup , role )
319- if err != nil {
235+ if err := r .pg .RevokeRole (currentGroup , role ); err != nil {
320236 return r .requeue (ctx , instance , errors .NewInternalError (err ))
321237 }
322238 }
323239
324240 // Grant the new group role
325- err = r .pg .GrantRole (desiredGroup , role )
326- if err != nil {
241+ if err := r .pg .GrantRole (desiredGroup , role ); err != nil {
327242 return r .requeue (ctx , instance , errors .NewInternalError (err ))
328243 }
329244
330245 // Ensure objects created by the user are owned by the new group
331- err = r .pg .AlterDefaultLoginRole (role , desiredGroup )
332- if err != nil {
246+ if err := r .pg .AlterDefaultLoginRole (role , desiredGroup ); err != nil {
333247 return r .requeue (ctx , instance , errors .NewInternalError (err ))
334248 }
335249
336250 instance .Status .PostgresGroup = desiredGroup
337- err = r .Status ().Update (ctx , instance )
338- if err != nil {
251+ if err := r .Status ().Update (ctx , instance ); err != nil {
339252 return r .requeue (ctx , instance , err )
340253 }
341254 }
0 commit comments