Skip to content

Commit

Permalink
Add new test to validate SPAWN_PROXY_TASK_CONFIG env
Browse files Browse the repository at this point in the history
  • Loading branch information
sleipnir committed Sep 28, 2024
1 parent 0b8d854 commit 2187c1b
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
} = _resource
) do
host_params = Map.get(params, "host")
task_actors_config = Map.get(host_params, "taskActors", %{})
task_actors_config = %{"taskActors" => Map.get(host_params, "taskActors", %{})}
topology = Map.get(params, "topology", %{})

replicas = max(1, Map.get(params, "replicas", @default_actor_host_function_replicas))
Expand Down Expand Up @@ -213,7 +213,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
actor_host_function_image = Map.get(host_params, "image")

actor_host_function_envs =
if length(Map.values(task_actors_config)) == 0 do
if is_nil(task_actors_config) || List.first(Map.values(task_actors_config)) == %{} do
Map.get(host_params, "env", []) ++ @default_actor_host_function_env
else
Map.get(host_params, "env", []) ++
Expand Down Expand Up @@ -279,7 +279,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
]

envs =
if length(Map.values(task_actors_config)) == 0 do
if is_nil(task_actors_config) || List.first(Map.values(task_actors_config)) == %{} do
@default_actor_host_function_env
else
@default_actor_host_function_env ++ build_task_env(task_actors_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ defmodule DeploymentTest do
simple_host_with_ports = build_simple_actor_host_with_ports()
simple_actor_host_with_volume_mounts = build_simple_actor_host_with_volume_mounts()
embedded_actor_host = build_embedded_actor_host()

embedded_actor_host_with_node_selector = build_embedded_actor_host_with_node_selector()
embedded_actor_host_with_task_actors = build_embedded_actor_host_with_task_actors()
embedded_actor_host_with_volume_mounts = build_embedded_actor_host_with_volume_mounts()

%{
Expand All @@ -20,6 +22,7 @@ defmodule DeploymentTest do
simple_actor_host_with_volume_mounts: simple_actor_host_with_volume_mounts,
embedded_actor_host: embedded_actor_host,
embedded_actor_host_with_node_selector: embedded_actor_host_with_node_selector,
embedded_actor_host_with_task_actors: embedded_actor_host_with_task_actors,
embedded_actor_host_with_volume_mounts: embedded_actor_host_with_volume_mounts
}
end
Expand Down Expand Up @@ -320,6 +323,155 @@ defmodule DeploymentTest do
} == build_host_deploy(embedded_actor_host_with_node_selector)
end

test "generate embedded deployment with defaults and node selector and task actors", ctx do
%{
embedded_actor_host_with_task_actors: embedded_actor_host_with_task_actors
} = ctx

assert %{
"apiVersion" => "apps/v1",
"kind" => "Deployment",
"metadata" => %{
"labels" => %{"actor-system" => "spawn-system", "app" => "spawn-test"},
"name" => "spawn-test",
"namespace" => "default"
},
"spec" => %{
"replicas" => 1,
"selector" => %{
"matchLabels" => %{"actor-system" => "spawn-system", "app" => "spawn-test"}
},
"strategy" => %{
"rollingUpdate" => %{"maxSurge" => "50%", "maxUnavailable" => 0},
"type" => "RollingUpdate"
},
"template" => %{
"metadata" => %{
"annotations" => %{
"prometheus.io/path" => "/metrics",
"prometheus.io/port" => "9001",
"prometheus.io/scrape" => "true"
},
"labels" => %{"actor-system" => "spawn-system", "app" => "spawn-test"}
},
"spec" => %{
"affinity" => %{
"podAffinity" => %{
"preferredDuringSchedulingIgnoredDuringExecution" => [
%{
"weight" => 50,
"podAffinityTerm" => %{
"labelSelector" => %{
"matchExpressions" => [
%{
"key" => "actor-system",
"operator" => "In",
"values" => [
"spawn-system"
]
}
]
},
"topologyKey" => "kubernetes.io/hostname"
}
}
]
},
"podAntiAffinity" => %{
"preferredDuringSchedulingIgnoredDuringExecution" => [
%{
"weight" => 100,
"podAffinityTerm" => %{
"labelSelector" => %{
"matchExpressions" => [
%{
"key" => "app",
"operator" => "In",
"values" => [
"spawn-test"
]
}
]
},
"topologyKey" => "kubernetes.io/hostname"
}
}
]
}
},
"containers" => [
%{
"env" => [
%{"name" => "RELEASE_NAME", "value" => "spawn"},
%{
"name" => "NAMESPACE",
"valueFrom" => %{
"fieldRef" => %{"fieldPath" => "metadata.namespace"}
}
},
%{
"name" => "POD_IP",
"valueFrom" => %{"fieldRef" => %{"fieldPath" => "status.podIP"}}
},
%{"name" => "SPAWN_PROXY_PORT", "value" => "9001"},
%{"name" => "SPAWN_PROXY_INTERFACE", "value" => "0.0.0.0"},
%{"name" => "RELEASE_DISTRIBUTION", "value" => "name"},
%{"name" => "RELEASE_NODE", "value" => "$(RELEASE_NAME)@$(POD_IP)"},
%{"name" => "SPAWN_PROXY_TASK_CONFIG", "value" => "PMRHIYLTNNAWG5DPOJZSEOS3PMRHAYLSMVXHITTBNVSSEORCJJXXGZJCFQRHI33QN5WG6Z3ZEI5HWITON5SGKU3FNRSWG5DPOIRDU6ZCM5YHKIR2EJTGC3DTMURH27L5LV6Q===="}
],
"envFrom" => [
%{"configMapRef" => %{"name" => "spawn-test-sidecar-cm"}},
%{"secretRef" => %{"name" => "spawn-system-secret"}}
],
"image" => "eigr/spawn-test:latest",
"name" => "actorhost",
"ports" => [
%{"containerPort" => 4369, "name" => "epmd"},
%{"containerPort" => 9001, "name" => "proxy-http"}
],
"resources" => %{
"requests" => %{
"cpu" => "100m",
"ephemeral-storage" => "1M",
"memory" => "80Mi"
}
},
"volumeMounts" => [%{"mountPath" => "/app/certs", "name" => "certs"}]
}
],
"terminationGracePeriodSeconds" => 405,
"initContainers" => [
%{
"args" => [
"--environment",
:prod,
"--secret",
"tls-certs",
"--namespace",
"default",
"--service",
"spawn-system",
"--to",
"default"
],
"image" => "ghcr.io/eigr/spawn-initializer:1.4.3",
"name" => "init-certificates"
}
],
"serviceAccountName" => "spawn-system-sa",
"volumes" => [
%{
"name" => "certs",
"secret" => %{"optional" => true, "secretName" => "tls-certs"}
}
],
"nodeSelector" => %{"gpu" => "false"}
}
}
}
} == build_host_deploy(embedded_actor_host_with_task_actors)
end

test "generate embedded deployment with volumeMount", ctx do
%{
embedded_actor_host_with_volume_mounts: embedded_actor_host_with_volume_mounts
Expand Down
34 changes: 34 additions & 0 deletions spawn_operator/spawn_operator/test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ defmodule SpawnOperator.FactoryTest do
}
end

def build_embedded_actor_host_with_task_actors(attrs \\ []) do
%{
"apiVersion" => "spawn-eigr.io/v1",
"kind" => "ActorHost",
"metadata" => %{
"name" => attrs[:name] || "spawn-test",
"system" => "spawn-system",
"namespace" => "default",
"generation" => 1
},
"spec" => %{
"topology" => %{
"nodeSelector" => %{
"gpu" => "false"
}
},
"host" => %{
"embedded" => true,
"image" => attrs[:host_image] || "eigr/spawn-test:latest",
"taskActors" => [
%{
"parentName" => "Jose",
"topology" => %{
"nodeSelector" => %{
"gpu" => "false"
}
}
}
]
}
}
}
end

def build_embedded_actor_host_with_volume_mounts(attrs \\ []) do
%{
"apiVersion" => "spawn-eigr.io/v1",
Expand Down

0 comments on commit 2187c1b

Please sign in to comment.