From bd9705ff9965425a8da4088cac2b23e2683c7b97 Mon Sep 17 00:00:00 2001 From: Haim Kortovich Date: Thu, 25 Jul 2024 12:53:50 -0500 Subject: [PATCH] Always add member instead [ZITADOPER-5] --- .../controller/organization_controller.go | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/internal/controller/organization_controller.go b/src/internal/controller/organization_controller.go index 4c4a520..8548677 100644 --- a/src/internal/controller/organization_controller.go +++ b/src/internal/controller/organization_controller.go @@ -199,20 +199,6 @@ func (wr *wrappedOrganizationReconciler) reconcileInitialAdmin(ctx context.Conte } } } - if adminClient != nil { - { - if _, err := adminClient.AddIAMMember(ctx, &adm.AddIAMMemberRequest{ - UserId: userid, - Roles: []string{ - "IAM_OWNER", - }, - }); err != nil { - if !strings.Contains(err.Error(), "RolesNotChanged") { - return fmt.Errorf("Error adding org member: %v", err) - } - } - } - } } else { userid = adminUser.User.Id @@ -231,6 +217,18 @@ func (wr *wrappedOrganizationReconciler) reconcileInitialAdmin(ctx context.Conte } if adminClient != nil { + { + if _, err := adminClient.AddIAMMember(ctx, &adm.AddIAMMemberRequest{ + UserId: userid, + Roles: []string{ + "IAM_OWNER", + }, + }); err != nil { + if !strings.Contains(err.Error(), "RolesNotChanged") || !strings.Contains(err.Error(), "AlreadyExists") { + return fmt.Errorf("Error adding org member: %v", err) + } + } + } { if _, err := adminClient.UpdateIAMMember(ctx, &adm.UpdateIAMMemberRequest{ UserId: userid,