Skip to content

Commit

Permalink
Switch to recursive subdomains instead of hyphens
Browse files Browse the repository at this point in the history
Mostly an aesthetic change, but I think i figured out what was happening w/ externaldns here.
  • Loading branch information
michaeljguarino committed Aug 21, 2024
1 parent 266b3a9 commit e97eee4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions apps/core/lib/core/clients/console.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,7 @@ defmodule Core.Clients.Console do

def repo(client, url) do
Req.post(client, graphql: {@repo_q, %{url: url}})
|> case do
{:ok, %Req.Response{body: %{"data" => %{"gitRepository" => %{"id" => id}}}}} -> {:ok, id}
res ->
Logger.warn "Failed to fetch clusters: #{inspect(res)}"
{:error, "could not fetch repo"}
end
|> service_resp("gitRepository")
end

def create_service(client, cluster_id, attrs) do
Expand All @@ -92,6 +87,7 @@ defmodule Core.Clients.Console do
def delete_service(client, id) do
Req.post(client, graphql: {@delete_svc_q, %{id: id}})
|> service_resp("deleteServiceDeployment")
|> ignore_not_found()
end

def stack(client, id) do
Expand All @@ -105,11 +101,16 @@ defmodule Core.Clients.Console do
end
end

defp ignore_not_found({:error, ["could not find resource" <> _ | _]}), do: {:ok, nil}
defp ignore_not_found(pass), do: pass

defp service_resp({:ok, %Req.Response{body: %{"errors" => [_ | _] = errors}}}, _), do: {:error, errors}
defp service_resp({:ok, %Req.Response{status: 200, body: %{"data" => body}}}, field) do
case body[field] do
%{"id" => id} -> {:ok, id}
err ->
Logger.warn "invalid console gql response: #{inspect(err)}"
{:error, "#{field} query failed"}
end
end

Expand Down
4 changes: 2 additions & 2 deletions apps/core/lib/core/services/cloud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Core.Services.Cloud do
Repositories.upsert_oidc_provider(%{
auth_method: :post,
bindings: Shell.oidc_bindings(inst.oidc_provider, user),
redirect_uris: Shell.merge_uris(["https://console-#{name}.cloud.plural.sh/oauth/callback"], inst.oidc_provider)
redirect_uris: Shell.merge_uris(["https://console.#{name}.cloud.plural.sh/oauth/callback"], inst.oidc_provider)
}, inst.id, sa)
end)
|> add_operation(:instance, fn %{oidc: oidc, token: token, cluster: cluster, postgres: roach, sa: sa} ->
Expand Down Expand Up @@ -135,7 +135,7 @@ defmodule Core.Services.Cloud do
end

defp add_configuration(attrs, name, token, %OIDCProvider{} = oidc, %User{} = user) do
Map.merge(attrs, %{subdomain: "#{name}.cloud.plural.sh", url: "console-#{name}.cloud.plural.sh"})
Map.merge(attrs, %{subdomain: "#{name}.cloud.plural.sh", url: "console.#{name}.cloud.plural.sh"})
|> Map.put(:configuration, %{
aes_key: aes_key(),
encryption_key: encryption_key(),
Expand Down
2 changes: 1 addition & 1 deletion apps/core/lib/core/services/cloud/workflow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule Core.Services.Cloud.Workflow do
defp down(%ConsoleInstance{instance_status: %{svc: true}} = inst) do
with {:ok, _} <- Console.delete_service(console(), inst.external_id) do
ConsoleInstance.changeset(inst, %{
instance_status: %{svc: false},
instance_status: %{svc: false, db: true},
status: :deployment_deleted,
})
|> Repo.update()
Expand Down

0 comments on commit e97eee4

Please sign in to comment.