Skip to content

Commit

Permalink
fix: correct cm
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Santos committed Jan 18, 2025
1 parent 16612c8 commit 9786246
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/spawn/cluster/cluster_resolver.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ defmodule Spawn.Cluster.ClusterResolver do
|> Enum.map(&:inet_parse.ntoa(&1))
|> Enum.map(&"#{app_name}@#{&1}")
|> Enum.map(&String.to_atom(&1))
IO.inspect(&1, label: "Parsed addresses ---------------------")
|> IO.inspect(label: "Parsed addresses ---------------------")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ defmodule SpawnOperator.K8s.Proxy.CM.Configmap do
# Optional. Default "true"
spawn-eigr.io/actors-global-backpressure-enabled: "true"
"""

@impl true
def manifest(resource, _opts \\ []), do: gen_configmap(resource)

Expand All @@ -107,7 +108,7 @@ defmodule SpawnOperator.K8s.Proxy.CM.Configmap do
system: system,
namespace: ns,
name: name,
params: _params,
params: params,
labels: _labels,
annotations: annotations
} = _resource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
defmodule SpawnOperator.K8s.Proxy.Deployment do
@moduledoc false

require Logger

import SpawnOperator.Utils

@behaviour SpawnOperator.K8s.Manifest

@default_actor_host_function_env [
Expand Down Expand Up @@ -84,13 +85,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do

@default_termination_period_seconds 405

@erlang_profiles %{
insecure_erl_flags:
"+C multi_time_warp -mode embedded +sbwt none +sbwtdcpu none +sbwtdio none",
tls_erl_flags:
" -proto_dist inet_tls -ssl_dist_optfile /app/mtls.ssl.conf +C multi_time_warp -mode embedded +sbwt none +sbwtdcpu none +sbwtdio none"
}

@impl true
def manifest(resource, _opts \\ []), do: gen_deployment(resource)

Expand All @@ -105,21 +99,13 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
} = _resource
) do
host_params = Map.get(params, "host")

cluster =
Map.get(params, "cluster", %{"features" => %{"erlangMtls" => %{"enabled" => false}}})
|> IO.inspect(label: "cluster")
IO.inspect(params, label: "spec")

erlang_mtls_enabled =
Map.get(cluster, "features", %{})
|> Map.get("erlangMtls", %{})
|> Map.get("enabled", false)
|> IO.inspect(label: "erlang_mtls_enabled")
System.get_env("ERL_CLUSTER_MTL_ENABLED", "false")
|> to_bool()

erlang_profile =
if erlang_mtls_enabled,
do: @erlang_profiles.tls_erl_flags,
else: @erlang_profiles.insecure_erl_flags
IO.inspect(erlang_mtls_enabled, label: "Erlang cluster tls enabled")

task_actors_config = %{"taskActors" => Map.get(host_params, "taskActors", %{})}
topology = Map.get(params, "topology", %{})
Expand Down Expand Up @@ -202,7 +188,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
host_params,
annotations,
task_actors_config,
erlang_profile,
erlang_mtls_enabled
),
"initContainers" => init_containers,
Expand Down Expand Up @@ -272,7 +257,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
host_params,
annotations,
task_actors_config,
flags,
erlang_mtls_enabled
) do
actor_host_function_image = Map.get(host_params, "image")
Expand All @@ -288,10 +272,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
"valueFrom" => %{
"secretKeyRef" => %{"name" => "#{system}-secret", "key" => "RELEASE_COOKIE"}
}
},
%{
"name" => "ERL_FLAGS",
"value" => flags
}
] ++ @default_actor_host_function_env

Expand Down Expand Up @@ -351,7 +331,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
host_params,
annotations,
task_actors_config,
flags,
erlang_mtls_enabled
) do
actor_host_function_image = Map.get(host_params, "image")
Expand All @@ -367,10 +346,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
"valueFrom" => %{
"secretKeyRef" => %{"name" => "#{system}-secret", "key" => "RELEASE_COOKIE"}
}
},
%{
"name" => "ERL_FLAGS",
"value" => flags
}
] ++ @default_actor_host_function_env

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do

import Bonny.Config, only: [conn: 0]

@erlang_profiles %{
insecure_erl_flags:
"+C multi_time_warp -mode embedded +sbwt none +sbwtdcpu none +sbwtdio none",
tls_erl_flags:
" -proto_dist inet_tls -ssl_dist_optfile /app/mtls.ssl.conf +C multi_time_warp -mode embedded +sbwt none +sbwtdcpu none +sbwtdio none"
}

@impl true
def manifest(resource, _opts \\ []), do: gen_secret(resource)

Expand All @@ -26,7 +33,7 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do

data =
Map.merge(distributed_options, storage_options)
|> maybe_use_nats_cluster(name, ns, params)
|> maybe_use_nats_cluster(name, ns, cluster_params)

%{
"apiVersion" => "v1",
Expand Down Expand Up @@ -85,9 +92,20 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
end

defp get_dist_options(system, ns, params) do

kind = Map.get(params, "kind", "erlang")

features =
Map.get(params, "features", %{"erlangMtls" => %{"enabled" => false}})

erlang_mtls_enabled =
Map.get(features, "erlangMtls", %{})
|> Map.get("enabled", false)

erlang_profile =
if erlang_mtls_enabled,
do: @erlang_profiles.tls_erl_flags,
else: @erlang_profiles.insecure_erl_flags

case String.to_existing_atom(kind) do
:erlang ->
cookie = Map.get(params, "cookie", default_cookie(ns)) |> Base.encode64()
Expand All @@ -97,6 +115,8 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
cluster_heartbeat = "240000" |> Base.encode64()

%{
"ERL_CLUSTER_MTL_ENABLED" => Base.encode64("#{erlang_mtls_enabled}"),
"ERL_FLAGS" => Base.encode64(erlang_profile),
"RELEASE_COOKIE" => cookie,
"PROXY_ACTOR_SYSTEM_NAME" => Base.encode64(system),
"PROXY_CLUSTER_POLLING" => cluster_poolling,
Expand All @@ -112,8 +132,6 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
%{
"PROXY_CLUSTER_STRATEGY" => cluster_strategy,
"PROXY_HEADLESS_SERVICE" => cluster_service
# "PROXY_TLS_CERT_PATH" => "",
# "PROXY_TLS_KEY_PATH" => ""
}

_other ->
Expand All @@ -122,28 +140,40 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
end

defp maybe_use_nats_cluster(config, _name, namespace, params) do
cluster_params = Map.get(params, "cluster", %{})
features = Map.get(cluster_params, "features", %{})
features =
Map.get(params, "features", %{
"nats" => %{
"enabled" => false,
"url" => "nats://nats.eigr-functions.svc.cluster.local:4222",
"credentialsSecretRef" => "nats-connectin-secret"
}
})

nats_params = Map.get(features, "nats", %{})
enabled = "#{Map.get(nats_params, "enabled", false)}"

nats_enabled =
Map.get(nats_params, "enabled")

nats_url =
Map.get(nats_params, "url")

nats_config =
case enabled do
"false" ->
case nats_enabled do
false ->
%{}

"true" ->
true ->
nats_secret_ref = Map.fetch!(nats_params, "credentialsSecretRef")

{:ok, secret} =
K8s.Client.get("v1", :secret,
namespace: namespace,
namespace: "eigr-functions",
name: nats_secret_ref
)
|> then(&K8s.Client.run(conn(), &1))

secret_data = Map.get(secret, "data")
nats_host_url = Map.get(secret_data, "url", nats_params["url"])
nats_host_url = nats_url |> Base.encode64()
nats_auth = Map.get(secret_data, "authEnabled", "false")
nats_user = Map.get(secret_data, "username")
nats_secret = Map.get(secret_data, "password")
Expand Down
7 changes: 7 additions & 0 deletions spawn_operator/spawn_operator/lib/spawn_operator/utils.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule SpawnOperator.Utils do
@moduledoc false

def to_bool("false"), do: false
def to_bool("true"), do: true
def to_bool(_), do: false
end

0 comments on commit 9786246

Please sign in to comment.