From b2cd48adb123d178ba521b30b7cfc5080747ece7 Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 8 Aug 2024 23:09:46 -0400 Subject: [PATCH] Need to b64 decode cockroach config secret forgot to add this as well --- Makefile | 4 +- apps/core/lib/core/clients/console.ex | 30 ++++++++- apps/core/lib/core/schema/console_instance.ex | 9 +-- ...ckroach_cluster.ex => postgres_cluster.ex} | 9 +-- apps/core/lib/core/services/cloud.ex | 27 ++++---- .../lib/core/services/cloud/configuration.ex | 15 ++--- apps/core/lib/core/services/cloud/poller.ex | 49 +++++++-------- apps/core/lib/core/services/cloud/workflow.ex | 61 ++++++++++--------- ...240810202736_rework_cockroach_clusters.exs | 13 ++++ .../migrations/20240811141716_fix_db_url.exs | 10 +++ .../test/services/cloud/workflow_test.exs | 10 ++- apps/core/test/services/cloud_test.exs | 6 +- apps/core/test/support/factory.ex | 12 ++-- apps/core/test/test_helper.exs | 1 + .../test/mutations/cloud_mutations_test.exs | 2 +- config/config.exs | 2 +- config/test.exs | 2 +- docker-compose.yml | 17 ++---- plural/helm/plural/Chart.yaml | 2 +- plural/helm/plural/templates/chartmuseum.yaml | 2 - rel/config/config.exs | 3 +- 21 files changed, 167 insertions(+), 119 deletions(-) rename apps/core/lib/core/schema/{cockroach_cluster.ex => postgres_cluster.ex} (74%) create mode 100644 apps/core/priv/repo/migrations/20240810202736_rework_cockroach_clusters.exs create mode 100644 apps/core/priv/repo/migrations/20240811141716_fix_db_url.exs diff --git a/Makefile b/Makefile index edfcf8044..2de0381e9 100644 --- a/Makefile +++ b/Makefile @@ -64,8 +64,8 @@ test-certs: cockroach cert create-client root --certs-dir test-certs --ca-key test-certs/ca.key && \ cockroach cert list --certs-dir test-certs -testup: test-certs ## sets up dependent services for test - docker compose up -d +testup: ## sets up dependent services for test + docker compose up -d --remove-orphans testdown: ## tear down test dependencies docker compose down diff --git a/apps/core/lib/core/clients/console.ex b/apps/core/lib/core/clients/console.ex index 1d4f3a3c7..fa65229ef 100644 --- a/apps/core/lib/core/clients/console.ex +++ b/apps/core/lib/core/clients/console.ex @@ -41,6 +41,18 @@ defmodule Core.Clients.Console do } """ + @stack_q """ + query Stack($id: ID!) { + infrastructureStack(id: $id) { + id + output { + name + value + } + } + } + """ + def new(url, token) do Req.new(base_url: with_gql(url), auth: "Token #{token}") |> AbsintheClient.attach() @@ -49,7 +61,8 @@ defmodule Core.Clients.Console do def clusters(client) do Req.post(client, graphql: @clusters_q) |> case do - {:ok, %Req.Response{body: %{"clusters" => %{"edges" => edges}}}} -> {:ok, Enum.map(edges, & &1["node"])} + {:ok, %Req.Response{body: %{"data" => %{"clusters" => %{"edges" => edges}}}}} -> + {:ok, Enum.map(edges, & &1["node"])} res -> Logger.warn "Failed to fetch clusters: #{inspect(res)}" {:error, "could not fetch clusters"} @@ -59,7 +72,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: %{"gitRepository" => %{"id" => id}}}} -> {:ok, id} + {:ok, %Req.Response{body: %{"data" => %{"gitRepository" => %{"id" => id}}}}} -> {:ok, id} res -> Logger.warn "Failed to fetch clusters: #{inspect(res)}" {:error, "could not fetch repo"} @@ -81,7 +94,18 @@ defmodule Core.Clients.Console do |> service_resp("deleteServiceDeployment") end - defp service_resp({:ok, %Req.Response{status: 200, body: body}}, field) do + def stack(client, id) do + Req.post(client, graphql: {@stack_q, %{id: id}}) + |> case do + {:ok, %Req.Response{body: %{"data" => %{"infrastructureStack" => stack}}}} -> + {:ok, stack} + res -> + Logger.warn "Failed to fetch stack: #{inspect(res)}" + {:error, "could not fetch stack"} + end + end + + defp service_resp({:ok, %Req.Response{status: 200, body: %{"data" => body}}}, field) do case body[field] do %{"id" => id} -> {:ok, id} err -> diff --git a/apps/core/lib/core/schema/console_instance.ex b/apps/core/lib/core/schema/console_instance.ex index 5dbd47d63..55e230333 100644 --- a/apps/core/lib/core/schema/console_instance.ex +++ b/apps/core/lib/core/schema/console_instance.ex @@ -1,7 +1,7 @@ defmodule Core.Schema.ConsoleInstance do use Piazza.Ecto.Schema alias Piazza.Ecto.EncryptedString - alias Core.Schema.{CockroachCluster, CloudCluster, User} + alias Core.Schema.{PostgresCluster, CloudCluster, User} defenum Size, small: 0, medium: 1, large: 2 defenum Status, @@ -41,6 +41,7 @@ defmodule Core.Schema.ConsoleInstance do field :dbpassword, EncryptedString field :subdomain, :string field :jwt_secret, EncryptedString + field :erlang_secret, EncryptedString field :owner_name, :string field :owner_email, :string field :admin_password, EncryptedString @@ -54,7 +55,7 @@ defmodule Core.Schema.ConsoleInstance do field :kas_redis, EncryptedString end - belongs_to :cockroach, CockroachCluster + belongs_to :postgres, PostgresCluster belongs_to :cluster, CloudCluster belongs_to :owner, User @@ -91,7 +92,7 @@ defmodule Core.Schema.ConsoleInstance do def regions(), do: @region_map - @valid ~w(name cloud size region status subdomain url external_id cockroach_id cluster_id owner_id)a + @valid ~w(name cloud size region status subdomain url external_id postgres_id cluster_id owner_id)a def changeset(model, attrs \\ %{}) do model @@ -117,7 +118,7 @@ defmodule Core.Schema.ConsoleInstance do end @conf_valid ~w( - database dbuser dbpassword + database dbuser dbpassword erlang_secret subdomain jwt_secret owner_name owner_email admin_password aes_key encryption_key client_id client_secret plural_token kas_api kas_private kas_redis diff --git a/apps/core/lib/core/schema/cockroach_cluster.ex b/apps/core/lib/core/schema/postgres_cluster.ex similarity index 74% rename from apps/core/lib/core/schema/cockroach_cluster.ex rename to apps/core/lib/core/schema/postgres_cluster.ex index 0e92016a5..01289ff42 100644 --- a/apps/core/lib/core/schema/cockroach_cluster.ex +++ b/apps/core/lib/core/schema/postgres_cluster.ex @@ -1,15 +1,16 @@ -defmodule Core.Schema.CockroachCluster do +defmodule Core.Schema.PostgresCluster do use Piazza.Ecto.Schema alias Piazza.Ecto.EncryptedString alias Core.Schema.CloudCluster @saturation 1000 - schema "cockroach_clusters" do + schema "postgres_clusters" do field :name, :string field :cloud, CloudCluster.Cloud field :region, :string field :url, EncryptedString + field :host, :string field :certificate, :string field :endpoints, :map field :count, :integer, default: 0 @@ -27,8 +28,8 @@ defmodule Core.Schema.CockroachCluster do def changeset(model, attrs \\ %{}) do model - |> cast(attrs, ~w(name cloud region url certificate endpoints)a) + |> cast(attrs, ~w(name cloud region url host certificate endpoints)a) |> unique_constraint(:name) - |> validate_required(~w(name cloud region url certificate endpoints)a) + |> validate_required(~w(name cloud url host)a) end end diff --git a/apps/core/lib/core/services/cloud.ex b/apps/core/lib/core/services/cloud.ex index 7a85a858d..c2308e30b 100644 --- a/apps/core/lib/core/services/cloud.ex +++ b/apps/core/lib/core/services/cloud.ex @@ -4,12 +4,12 @@ defmodule Core.Services.Cloud do alias Core.Repo alias Core.PubSub alias Core.Services.{Accounts, Users, Repositories, Shell} - alias Core.Schema.{CloudCluster, CockroachCluster, ConsoleInstance, User, OIDCProvider} + alias Core.Schema.{CloudCluster, PostgresCluster, ConsoleInstance, User, OIDCProvider} @type error :: {:error, term} @type console_resp :: {:ok, ConsoleInstance.t} | error @type cluster_resp :: {:ok, CloudCluster.t} | error - @type cockroach_resp :: {:ok, CockroachCluster.t} | error + @type postgres_resp :: {:ok, PostgresCluster.t} | error def get_instance!(id), do: Repo.get!(ConsoleInstance, id) @@ -23,13 +23,13 @@ defmodule Core.Services.Cloud do |> Repo.insert_or_update() end - @spec upsert_cockroach(map, binary) :: cockroach_resp - def upsert_cockroach(attrs, name) do - case Repo.get_by(CockroachCluster, name: name) do - %CockroachCluster{} = cluster -> cluster - nil -> %CockroachCluster{name: name} + @spec upsert_postgres(map, binary) :: postgres_resp + def upsert_postgres(attrs, name) do + case Repo.get_by(PostgresCluster, name: name) do + %PostgresCluster{} = cluster -> cluster + nil -> %PostgresCluster{name: name} end - |> CockroachCluster.changeset(attrs) + |> PostgresCluster.changeset(attrs) |> Repo.insert_or_update() end @@ -41,7 +41,7 @@ defmodule Core.Services.Cloud do start_transaction() |> add_operation(:auth, fn _ -> allow(%ConsoleInstance{}, user, :create) end) |> add_operation(:cluster, fn _ -> select_cluster(attrs[:cloud], attrs[:region]) end) - |> add_operation(:cockroach, fn _ -> select_roach(attrs[:cloud]) end) + |> add_operation(:postgres, fn _ -> select_roach(attrs[:cloud]) end) |> add_operation(:sa, fn _ -> Accounts.create_service_account(%{name: "#{name}-cloud-sa", email: "#{name}-cloud-sa@srv.plural.sh"}, user) end) @@ -61,8 +61,8 @@ defmodule Core.Services.Cloud do 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, cockroach: roach, sa: sa} -> - %ConsoleInstance{status: :pending, cluster_id: cluster.id, cockroach_id: roach.id, owner_id: sa.id} + |> add_operation(:instance, fn %{oidc: oidc, token: token, cluster: cluster, postgres: roach, sa: sa} -> + %ConsoleInstance{status: :pending, cluster_id: cluster.id, postgres_id: roach.id, owner_id: sa.id} |> ConsoleInstance.changeset(add_configuration(attrs, name, token.token, oidc, user)) |> Repo.insert() end) @@ -147,6 +147,7 @@ defmodule Core.Services.Cloud do owner_name: user.name, owner_email: user.email, admin_password: Core.random_alphanum(30), + erlang_secret: Core.random_alphanum(30), client_id: oidc.client_id, client_secret: oidc.client_secret, plural_token: token, @@ -165,8 +166,8 @@ defmodule Core.Services.Cloud do end defp select_roach(cloud) do - CockroachCluster.for_cloud(cloud) - |> CockroachCluster.unsaturated() + PostgresCluster.for_cloud(cloud) + |> PostgresCluster.unsaturated() |> Repo.all() |> random_choice("Could not place in #{cloud}") end diff --git a/apps/core/lib/core/services/cloud/configuration.ex b/apps/core/lib/core/services/cloud/configuration.ex index 74140670c..b16dfa7a7 100644 --- a/apps/core/lib/core/services/cloud/configuration.ex +++ b/apps/core/lib/core/services/cloud/configuration.ex @@ -1,5 +1,5 @@ defmodule Core.Services.Cloud.Configuration do - alias Core.Schema.{ConsoleInstance, CockroachCluster} + alias Core.Schema.{ConsoleInstance, PostgresCluster} def build(%ConsoleInstance{configuration: conf, size: size} = inst) do Map.take(conf, ~w( @@ -16,23 +16,24 @@ defmodule Core.Services.Cloud.Configuration do kas_api kas_private kas_redis + erlang_secret )a) |> Map.merge(%{ postgres_url: build_pg_url(inst), + cloud: "#{inst.cloud}", + cluster_name: inst.name, size: "#{size}", - postgres_certificate: certificate(inst) }) |> Map.put(:size, "#{size}") - |> Enum.map(fn {k, v} -> %{name: Macro.camelize("#{k}"), value: v} end) + |> Enum.map(fn {k, v} -> %{name: k, value: v} end) end - defp certificate(%ConsoleInstance{cockroach: %CockroachCluster{certificate: cert}}), do: cert + # defp certificate(%ConsoleInstance{postgres: %PostgresCluster{certificate: cert}}), do: cert defp build_pg_url(%ConsoleInstance{ configuration: %{dbuser: u, dbpassword: p, database: database}, - region: region, - cockroach: %CockroachCluster{endpoints: endpoints} + postgres: %PostgresCluster{host: host} }) do - "postgresql://#{u}:#{p}@#{endpoints[region]}/#{database}" + "postgresql://#{u}:#{p}@#{host}/#{database}" end end diff --git a/apps/core/lib/core/services/cloud/poller.ex b/apps/core/lib/core/services/cloud/poller.ex index 46c35fb5e..396a0fca0 100644 --- a/apps/core/lib/core/services/cloud/poller.ex +++ b/apps/core/lib/core/services/cloud/poller.ex @@ -2,10 +2,9 @@ defmodule Core.Services.Cloud.Poller do use GenServer alias Core.Clients.Console alias Core.Services.Cloud - alias Kazan.Apis.Core.V1, as: CoreV1 require Logger - @poll :timer.minutes(5) + @poll :timer.minutes(2) defmodule State, do: defstruct [:client, :repo] @@ -15,16 +14,16 @@ defmodule Core.Services.Cloud.Poller do def init(_) do :timer.send_interval(@poll, :clusters) - :timer.send_interval(@poll, :roaches) + :timer.send_interval(@poll, :pgs) send self(), :repo {:ok, %State{client: Console.new(Core.conf(:console_url), Core.conf(:console_token))}} end def repository(), do: GenServer.call(__MODULE__, :repo) - def handle_call(:repo, %{repo: id} = state) when is_binary(id), + def handle_call(:repo, _, %{repo: id} = state) when is_binary(id), do: {:reply, {:ok, id}, state} - def handle_call(:repo, state), do: {:reply, {:error, "repo not pulled"}, state} + def handle_call(:repo, _, state), do: {:reply, {:error, "repo not pulled"}, state} def handle_info(:repo, %{client: client} = state) do case Console.repo(client, Core.conf(:mgmt_repo)) do @@ -43,12 +42,13 @@ defmodule Core.Services.Cloud.Poller do {:noreply, state} end - def handle_info(:roaches, state) do - case read_secret() do - {:ok, roaches} -> - Enum.each(roaches, &upsert_roach/1) - err -> - Logger.warn "failed to fetch available cockroach clusters: #{inspect(err)}" + def handle_info(:pgs, %{client: client} = state) do + with {:ok, stack} <- Console.stack(client, Core.conf(:stack_id)), + %{"value" => v} <- Enum.find(stack["output"], & &1["name"] == "clusters"), + {:ok, pgs} <- Jason.decode(v) do + Enum.each(pgs, fn {k, v} -> upsert_pg(k, v) end) + else + err -> Logger.warn "failed to fetch cluster info: #{inspect(err)}" end {:noreply, state} end @@ -61,29 +61,24 @@ defmodule Core.Services.Cloud.Poller do cloud: to_cloud(distro), region: meta["region"] }, name) + |> log_err("failed to insert cloud cluster") end - defp upsert_roach(%{"name" => name} = roach) do - Cloud.upsert_cockroach(%{ - cloud: roach["cloud"], - url: roach["url"], - certificate: roach["certificate"], - endpoints: roach["endpoints"] + defp upsert_pg(name, pg) do + Cloud.upsert_postgres(%{ + cloud: pg["cloud"], + url: pg["url"], + # certificate: pg["certificate"], + host: pg["host"] }, name) - end - - defp read_secret() do - CoreV1.read_namespaced_secret!("plural", "plrl-cloud-config") - |> Kazan.run() - |> case do - {:ok, %CoreV1.Secret{data: %{"cockroaches" => roaches}}} -> - Jason.decode(roaches) - _ -> {:error, "could not find secret"} - end + |> log_err("failed to insert postgres cluster") end defp to_cloud("EKS"), do: :aws defp to_cloud("GKE"), do: :gcp defp to_cloud("AKS"), do: :azure defp to_cloud(_), do: :aws + + defp log_err({:error, _} = err, msg), do: "#{msg}: #{inspect(err)}" + defp log_err(pass, _), do: pass end diff --git a/apps/core/lib/core/services/cloud/workflow.ex b/apps/core/lib/core/services/cloud/workflow.ex index 3c626ead3..ab3564ba6 100644 --- a/apps/core/lib/core/services/cloud/workflow.ex +++ b/apps/core/lib/core/services/cloud/workflow.ex @@ -1,15 +1,15 @@ defmodule Core.Services.Cloud.Workflow do use Core.Services.Base alias Core.Clients.Console - alias Core.Services.Cloud + alias Core.Services.{Cloud, Users} alias Core.Services.Cloud.{Poller, Configuration} - alias Core.Schema.{ConsoleInstance, CockroachCluster} + alias Core.Schema.{ConsoleInstance, PostgresCluster, User} alias Core.Repo require Logger def sync(%ConsoleInstance{external_id: id} = instance) when is_binary(id) do - instance = Repo.preload(instance, [:cluster, :cockroach]) + instance = Repo.preload(instance, [:cluster, :postgres]) Console.update_service(console(), %{ size: instance.size, configuration: Configuration.build(instance) @@ -18,7 +18,7 @@ defmodule Core.Services.Cloud.Workflow do def sync(_), do: :ok def provision(%ConsoleInstance{} = instance) do - instance = Repo.preload(instance, [:cockroach, :cluster]) + instance = Repo.preload(instance, [:postgres, :cluster]) Enum.reduce_while(0..10, instance, fn _, acc -> case up(acc) do @@ -34,7 +34,7 @@ defmodule Core.Services.Cloud.Workflow do end def deprovision(%ConsoleInstance{} = instance) do - instance = Repo.preload(instance, [:cockroach, :cluster]) + instance = Repo.preload(instance, [:postgres, :cluster]) Enum.reduce_while(0..10, instance, fn _, acc -> case down(acc) do @@ -49,11 +49,11 @@ defmodule Core.Services.Cloud.Workflow do |> finalize(:down) end - defp up(%ConsoleInstance{status: :pending, cockroach: roach, configuration: conf} = inst) do - with {:ok, pid} <- connect(roach), + defp up(%ConsoleInstance{status: :pending, postgres: pg, configuration: conf} = inst) do + with {:ok, pid} <- connect(pg), + _ <- Postgrex.query!(pid, "CREATE DATABASE #{conf.database}", []), {:ok, _} <- Postgrex.transaction(pid, fn conn -> - Postgrex.query!(conn, "CREATE DATABASE #{conf.database}", []) - Postgrex.query!(conn, "CREATE USER #{conf.dbuser} WITH PASSWORD $1", [conf.dbpassword]) + Postgrex.query!(conn, "CREATE USER #{conf.dbuser} WITH PASSWORD '#{conf.dbpassword}'", []) Postgrex.query!(conn, "GRANT ALL ON DATABASE #{conf.database} TO #{conf.dbuser}", []) end) do ConsoleInstance.changeset(inst, %{ @@ -88,11 +88,11 @@ defmodule Core.Services.Cloud.Workflow do end end - defp down(%ConsoleInstance{instance_status: %{svc: false, db: true}, configuration: conf, cockroach: roach} = inst) do - with {:ok, pid} <- connect(roach), + defp down(%ConsoleInstance{instance_status: %{svc: false, db: true}, configuration: conf, postgres: pg} = inst) do + with {:ok, pid} <- connect(pg), + _ <- Postgrex.query!(pid, "DROP DATABASE IF EXISTS #{conf.database}", []), {:ok, _} <- Postgrex.transaction(pid, fn conn -> - Postgrex.query!(conn, "DROP DATABASE #{conf.database}", []) - Postgrex.query!(conn, "DROP USER #{conf.dbuser}", []) + Postgrex.query!(conn, "DROP USER IF EXISTS #{conf.dbuser}", []) end) do ConsoleInstance.changeset(inst, %{ instance_status: %{db: false}, @@ -117,11 +117,17 @@ defmodule Core.Services.Cloud.Workflow do |> Repo.update() end - defp finalize(%ConsoleInstance{status: :database_deleted, cluster: cluster, cockroach: roach} = inst, :down) do + defp finalize(%ConsoleInstance{status: :database_deleted, cluster: cluster, postgres: pg} = inst, :down) do start_transaction() |> add_operation(:inst, fn _ -> Repo.delete(inst) end) |> add_operation(:cluster, fn _ -> Cloud.dec(cluster) end) - |> add_operation(:roach, fn _ -> Cloud.dec(roach) end) + |> add_operation(:pg, fn _ -> Cloud.dec(pg) end) + |> add_operation(:sa, fn %{inst: %{name: name}} -> + case Users.get_user_by_email("#{name}-cloud-sa@srv.plural.sh") do + %User{} = u -> Repo.delete(u) + _ -> {:ok, nil} + end + end) |> execute(extract: :inst) end @@ -130,20 +136,17 @@ defmodule Core.Services.Cloud.Workflow do {:ok, inst} end - defp connect(%CockroachCluster{certificate: cert_pem} = roach) do - with [cert | _] <- :public_key.pem_decode(cert_pem) do - uri = URI.parse(roach.url) - user = userinfo(uri) - Postgrex.start_link( - database: uri.path && String.trim_leading(uri.path, "/"), - username: user[:username], - password: user[:password], - hostname: uri.host, - port: uri.port, - ssl: true, - ssl_opts: [cacerts: [:public_key.pem_entry_decode(cert)]] - ) - end + defp connect(%PostgresCluster{} = roach) do + uri = URI.parse(roach.url) + user = userinfo(uri) + Postgrex.start_link( + database: uri.path && String.trim_leading(uri.path, "/"), + username: user[:username], + password: user[:password], + hostname: uri.host, + port: uri.port, + ssl: Core.conf(:bootstrap_ssl) + ) end defp userinfo(%URI{userinfo: info}) when is_binary(info) do diff --git a/apps/core/priv/repo/migrations/20240810202736_rework_cockroach_clusters.exs b/apps/core/priv/repo/migrations/20240810202736_rework_cockroach_clusters.exs new file mode 100644 index 000000000..2b2b7c428 --- /dev/null +++ b/apps/core/priv/repo/migrations/20240810202736_rework_cockroach_clusters.exs @@ -0,0 +1,13 @@ +defmodule Core.Repo.Migrations.ReworkCockroachClusters do + use Ecto.Migration + + def change do + rename table(:cockroach_clusters), to: table(:postgres_clusters) + + alter table(:postgres_clusters) do + add :host, :string + end + + rename table(:console_instances), :cockroach_id, to: :postgres_id + end +end diff --git a/apps/core/priv/repo/migrations/20240811141716_fix_db_url.exs b/apps/core/priv/repo/migrations/20240811141716_fix_db_url.exs new file mode 100644 index 000000000..be27c43fd --- /dev/null +++ b/apps/core/priv/repo/migrations/20240811141716_fix_db_url.exs @@ -0,0 +1,10 @@ +defmodule Core.Repo.Migrations.FixDbUrl do + use Ecto.Migration + + def change do + alter table(:postgres_clusters) do + remove :url + add :url, :binary + end + end +end diff --git a/apps/core/test/services/cloud/workflow_test.exs b/apps/core/test/services/cloud/workflow_test.exs index 105717a88..4c006841c 100644 --- a/apps/core/test/services/cloud/workflow_test.exs +++ b/apps/core/test/services/cloud/workflow_test.exs @@ -9,7 +9,7 @@ defmodule Core.Services.Cloud.WorkflowTest do enable_features(account, [:cd]) user = admin_user(account) %{external_id: cluster_id} = cluster = insert(:cloud_cluster) - roach = insert(:cockroach_cluster) + roach = insert(:postgres_cluster) insert(:repository, name: "console") expect(HTTPoison, :post, fn _, _, _ -> @@ -24,7 +24,9 @@ defmodule Core.Services.Cloud.WorkflowTest do }, user) expect(Core.Services.Cloud.Poller, :repository, fn -> {:ok, "some-id"} end) - expect(Core.Clients.Console, :create_service, fn _, ^cluster_id, _ -> {:ok, Ecto.UUID.generate()} end) + expect(Req, :post, fn _, [graphql: {_, %{clusterId: ^cluster_id}}] -> + {:ok, %Req.Response{status: 200, body: %{"data" => %{"createServiceDeployment" => %{"id" => Ecto.UUID.generate()}}}}} + end) {:ok, %{external_id: svc_id} = instance} = Workflow.provision(instance) @@ -32,7 +34,9 @@ defmodule Core.Services.Cloud.WorkflowTest do assert instance.instance_status.db assert instance.instance_status.svc - expect(Core.Clients.Console, :delete_service, fn _, ^svc_id -> {:ok, svc_id} end) + expect(Req, :post, fn _, [graphql: {_, %{id: ^svc_id}}] -> + {:ok, %Req.Response{status: 200, body: %{"data" => %{"deleteServiceDeployment" => %{"id" => svc_id}}}}} + end) {:ok, instance} = Workflow.deprovision(instance) diff --git a/apps/core/test/services/cloud_test.exs b/apps/core/test/services/cloud_test.exs index e64f7aaab..bd84ca7ce 100644 --- a/apps/core/test/services/cloud_test.exs +++ b/apps/core/test/services/cloud_test.exs @@ -10,7 +10,7 @@ defmodule Core.Services.CloudTest do enable_features(account, [:cd]) user = admin_user(account) cluster = insert(:cloud_cluster) - cockroach = insert(:cockroach_cluster) + postgres = insert(:postgres_cluster) insert(:repository, name: "console") expect(HTTPoison, :post, fn _, _, _ -> @@ -30,7 +30,7 @@ defmodule Core.Services.CloudTest do assert instance.size == :small assert refetch(cluster).count == 1 - assert refetch(cockroach).count == 1 + assert refetch(postgres).count == 1 assert_receive {:event, %PubSub.ConsoleInstanceCreated{item: ^instance}} end @@ -39,7 +39,7 @@ defmodule Core.Services.CloudTest do account = insert(:account) user = admin_user(account) insert(:cloud_cluster) - insert(:cockroach_cluster) + insert(:postgres_cluster) insert(:repository, name: "console") {:error, "you must be on a paid plan to use Plural Cloud"} = Cloud.create_instance(%{ diff --git a/apps/core/test/support/factory.ex b/apps/core/test/support/factory.ex index 41435fe31..ce872362e 100644 --- a/apps/core/test/support/factory.ex +++ b/apps/core/test/support/factory.ex @@ -650,7 +650,7 @@ defmodule Core.Factory do status: :provisioned, size: :small, cluster: build(:cloud_cluster), - cockroach: build(:cockroach_cluster), + postgres: build(:postgres_cluster), owner: build(:user, service_account: true), subdomain: "#{name}.cloud.plural.sh", url: "console.#{name}.cloud.plural.sh", @@ -668,12 +668,12 @@ defmodule Core.Factory do } end - def cockroach_cluster_factory do - %Schema.CockroachCluster{ - name: sequence(:cockroach, & "cockroach-#{&1}"), + def postgres_cluster_factory do + %Schema.PostgresCluster{ + name: sequence(:postgres, & "pg-#{&1}"), cloud: :aws, - url: "postgresql://plrl:plural@localhost:26257/plural", - certificate: File.read!("../../test-certs/client.root.crt") + url: "postgresql://postgres:postgres@localhost:5433/postgres", + host: "localhost:5433" } end diff --git a/apps/core/test/test_helper.exs b/apps/core/test/test_helper.exs index fa1d67468..da5d8b514 100644 --- a/apps/core/test/test_helper.exs +++ b/apps/core/test/test_helper.exs @@ -35,5 +35,6 @@ Mimic.copy(System) Mimic.copy(Core.Clients.Vault) Mimic.copy(Core.Clients.Console) Mimic.copy(Core.Services.Cloud.Poller) +Mimic.copy(Req) {:ok, _} = Application.ensure_all_started(:ex_machina) diff --git a/apps/graphql/test/mutations/cloud_mutations_test.exs b/apps/graphql/test/mutations/cloud_mutations_test.exs index 98d2b1ccc..ee718507a 100644 --- a/apps/graphql/test/mutations/cloud_mutations_test.exs +++ b/apps/graphql/test/mutations/cloud_mutations_test.exs @@ -9,7 +9,7 @@ defmodule GraphQl.CloudMutationsTest do enable_features(account, [:cd]) user = admin_user(account) insert(:cloud_cluster) - insert(:cockroach_cluster) + insert(:postgres_cluster) insert(:repository, name: "console") expect(HTTPoison, :post, fn _, _, _ -> diff --git a/config/config.exs b/config/config.exs index 6edf601e0..40f67b617 100644 --- a/config/config.exs +++ b/config/config.exs @@ -146,7 +146,7 @@ config :core, sysbox_emails: [], mgmt_repo: "https://github.com/pluralsh/plural.git", cockroach_parameters: [], - cockroach_ssl: true + bootstrap_ssl: true config :briefly, directory: [{:system, "TMPDIR"}, {:system, "TMP"}, {:system, "TEMP"}, "/tmp"], diff --git a/config/test.exs b/config/test.exs index b730ec8b2..ad42eb1da 100644 --- a/config/test.exs +++ b/config/test.exs @@ -92,4 +92,4 @@ config :core, enforce_pricing: true, sysbox_emails: ["sysbox@plural.sh"], cockroach_parameters: [sslmode: "allow"], - cockroach_ssl: true + bootstrap_ssl: false diff --git a/docker-compose.yml b/docker-compose.yml index 1130b6cdc..a3e7f5573 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,20 +8,15 @@ services: POSTGRES_PASSWORD: postgres volumes: - database_data:/var/lib/postgresql/data - cockroach: - image: cockroachdb/cockroach:v24.1.3 + cloud: + image: postgres:14 restart: always ports: - - 26257:26257 - - 8080:8080 - command: start-single-node --certs-dir /cockroach/certs + - 5433:5432 environment: - - COCKROACH_DATABASE=plural - - COCKROACH_USER=plrl - - COCKROACH_PASSWORD=plural + POSTGRES_PASSWORD: postgres volumes: - - roach_data:/cockroach/cockroach-data - - ./test-certs:/cockroach/certs + - cld_db_data:/var/lib/postgresql/data rabbit: image: rabbitmq:3-management hostname: "rabbit1" @@ -64,7 +59,7 @@ services: volumes: database_data: driver: local - roach_data: + cld_db_data: driver: local influxdb: driver: local \ No newline at end of file diff --git a/plural/helm/plural/Chart.yaml b/plural/helm/plural/Chart.yaml index 4db7f4669..7ef92f4c2 100644 --- a/plural/helm/plural/Chart.yaml +++ b/plural/helm/plural/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: plural description: A helm chart for installing plural appVersion: 0.11.8 -version: 0.10.93 +version: 0.10.94 dependencies: - name: hydra version: 0.26.5 diff --git a/plural/helm/plural/templates/chartmuseum.yaml b/plural/helm/plural/templates/chartmuseum.yaml index ba31e5f3c..04e62b72e 100644 --- a/plural/helm/plural/templates/chartmuseum.yaml +++ b/plural/helm/plural/templates/chartmuseum.yaml @@ -28,8 +28,6 @@ spec: env: - name: PORT value: '8080' - - name: DEPLOYED_AT - value: {{ now | unixEpoch | quote }} - name: DEPTH value: '1' - name: CONTEXT_PATH diff --git a/rel/config/config.exs b/rel/config/config.exs index 28130f082..7a1b29000 100644 --- a/rel/config/config.exs +++ b/rel/config/config.exs @@ -93,7 +93,8 @@ config :core, github_demo_token: get_env("GITHUB_DEMO_TOKEN"), console_token: get_env("CONSOLE_SA_TOKEN"), console_url: get_env("CONSOLE_URL"), - mgmt_repo: get_env("CONSOLE_MGMT_REPO") + mgmt_repo: get_env("CONSOLE_MGMT_REPO"), + stack_id: get_env("CONSOLE_CLOUD_STACK_ID") if get_env("VAULT_HOST") do