Skip to content

Commit

Permalink
provisioning: trigger a reconciliation when the tenant gets created
Browse files Browse the repository at this point in the history
Signed-off-by: Riccardo Binetti <[email protected]>
  • Loading branch information
rbino committed Nov 6, 2023
1 parent 322b083 commit fd80c28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backend/lib/edgehog/provisioning.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ defmodule Edgehog.Provisioning do

defp create_tenant(tenant_config) do
tenant_params = Map.take(tenant_config, [:name, :slug, :public_key])
Tenants.create_tenant(tenant_params)

with {:ok, tenant} <- Tenants.create_tenant(tenant_params) do
Tenants.preload_astarte_resources_for_tenant(tenant)
|> Tenants.reconcile_tenant()

{:ok, tenant}
end
end

defp fetch_or_create_cluster(astarte_config) do
Expand Down
5 changes: 5 additions & 0 deletions backend/lib/edgehog/tenants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule Edgehog.Tenants do
import Ecto.Query, warn: false
alias Edgehog.Repo

alias Edgehog.Tenants.Reconciler
alias Edgehog.Tenants.Tenant

@doc """
Expand Down Expand Up @@ -147,6 +148,10 @@ defmodule Edgehog.Tenants do
Repo.preload(tenant_or_tenants, [realm: [:cluster]], skip_tenant_id: true)
end

def reconcile_tenant(%Tenant{} = tenant) do
Reconciler.reconcile_tenant(tenant)
end

@doc """
Returns an `%Astarte.Client.RealmManagement{}` for the given tenant.
Expand Down

0 comments on commit fd80c28

Please sign in to comment.