Add organization manifests

[ZITADOPER-1]
This commit is contained in:
Haim Kortovich
2024-05-16 20:15:14 -05:00
parent 3a691bb491
commit 56ec6aa9b1
3 changed files with 93 additions and 9 deletions

View File

@@ -91,19 +91,31 @@ func newWrappedOrganizationReconciler(client client.Client, refResolver *zitadel
}
func (wr *wrappedOrganizationReconciler) Reconcile(ctx context.Context, ztdClient *management.Client) error {
// TODO: check if org exists first
resp, err := ztdClient.AddOrg(ctx, &pb.AddOrgRequest{
Name: wr.organization.Name,
zitadelCluster, err := wr.refResolver.ZitadelCluster(ctx, &wr.organization.Spec.ZitadelClusterRef, wr.organization.Namespace)
if err != nil {
return err
}
orgRes, err := ztdClient.GetOrgByDomainGlobal(ctx, &pb.GetOrgByDomainGlobalRequest{
Domain: strings.ToLower(fmt.Sprintf("%s.%s", wr.organization.Name, zitadelCluster.Spec.Host)),
})
if err != nil {
if strings.Contains(err.Error(), "AlreadyExists") {
return nil
if !strings.Contains(err.Error(), "not found") {
return fmt.Errorf("Error getting org: %v", err)
}
return fmt.Errorf("error creating organization in Zitadel: %v", err)
}
patch := ctrlClient.MergeFrom(wr.organization.DeepCopy())
wr.organization.Status.OrgId = resp.Id
return wr.Client.Status().Patch(ctx, wr.organization, patch)
// TODO: add initial user
if orgRes == nil {
resp, err := ztdClient.AddOrg(ctx, &pb.AddOrgRequest{
Name: strings.ToLower(wr.organization.Name),
})
if err != nil {
return fmt.Errorf("error creating organization in Zitadel: %v", err)
}
patch := ctrlClient.MergeFrom(wr.organization.DeepCopy())
wr.organization.Status.OrgId = resp.Id
return wr.Client.Status().Patch(ctx, wr.organization, patch)
}
return nil
}
func (wr *wrappedOrganizationReconciler) PatchStatus(ctx context.Context, patcher condition.Patcher) error {