77 "encoding/hex"
88 "fmt"
99 "hash/fnv"
10+ "time"
1011
1112 apierrors "k8s.io/apimachinery/pkg/api/errors"
1213 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -129,6 +130,13 @@ func (r *PersonalOrganizationController) Reconcile(ctx context.Context, req ctrl
129130 return ctrl.Result {}, fmt .Errorf ("failed to create or update organization membership: %w" , err )
130131 }
131132
133+ // If the user is not active, we should not create a personal project,
134+ // as the impersonated client will not have the correct permissions.
135+ if user .Status .RegistrationApproval != iamv1alpha1 .RegistrationApprovalStateApproved {
136+ logger .Info ("User is not active, skipping personal project creation" , "user" , user .Name , "state" , user .Status .State )
137+ return ctrl.Result {RequeueAfter : 5 * time .Second }, nil
138+ }
139+
132140 // Create a default personal project in the personal organization.
133141 personalProjectID := hashPersonalOrgName (string (user .UID ))
134142 personalProject := & resourcemanagerv1alpha1.Project {
@@ -153,7 +161,7 @@ func (r *PersonalOrganizationController) Reconcile(ctx context.Context, req ctrl
153161 // sees the correct identity and creates the right PolicyBinding.
154162 impersonatedConfig := rest .CopyConfig (r .RestConfig )
155163 impersonatedConfig .Impersonate = rest.ImpersonationConfig {
156- UserName : user .Name ,
164+ UserName : user .Spec . Email ,
157165 UID : user .Name ,
158166 Groups : []string {"system:authenticated" },
159167 Extra : map [string ][]string {
0 commit comments