Skip to content

Commit 1d6e291

Browse files
author
Adriano Santos
committed
feat: create init container to copy protobuf files from actorhosts
1 parent 13dcb65 commit 1d6e291

File tree

6 files changed

+756
-225
lines changed

6 files changed

+756
-225
lines changed

spawn_operator/spawn_operator/lib/spawn_operator/k8s/proxy/deployment.ex

+48-18
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
6262
}
6363
}
6464

65+
@file_shared_volume %{
66+
"name" => "shared-volume",
67+
"emptyDir" => %{}
68+
}
69+
70+
@file_protos_volume %{
71+
"name" => "proto-volume",
72+
"emptyDir" => %{}
73+
}
74+
75+
@default_certs_volume %{
76+
"name" => "certs",
77+
"secret" => %{"secretName" => "tls-certs", "optional" => true}
78+
}
79+
80+
@default_volumes [
81+
@default_certs_volume,
82+
@file_shared_volume,
83+
@file_protos_volume
84+
]
85+
86+
@file_copy_volume_mounts [
87+
%{"name" => "shared-volume", "mountPath" => "/shared-volume"},
88+
%{"name" => "proto-volume", "mountPath" => "/actors"}
89+
]
90+
91+
@default_certs_volume_mounts %{"name" => "certs", "mountPath" => "/app/certs"}
92+
93+
@default_volume_mounts [
94+
@default_certs_volume_mounts
95+
96+
] ++ @file_copy_volume_mounts
97+
6598
@default_termination_period_seconds 405
6699

67100
@impl true
@@ -134,9 +167,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
134167
%{
135168
"name" => "init-certificates",
136169
"image" => "#{annotations.proxy_init_container_image_tag}",
137-
"env" => [
138-
%{"containerPort" => 4369, "name" => "epmd"}
139-
],
140170
"args" => [
141171
"--environment",
142172
:prod,
@@ -155,6 +185,16 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
155185
"value" => "none"
156186
}
157187
]
188+
},
189+
%{
190+
"name" => "copy-proto-files",
191+
"image" => "alpine:3.20",
192+
"command" => ["/bin/sh", "-c"],
193+
"args" => [
194+
#"if [ -d /actors ]; then cp -r /actors/* /shared-volume/; else echo 'Source folder not found!' && exit 1; fi"
195+
"ls -ltra /"
196+
],
197+
"volumeMounts" => @default_volume_mounts
158198
}
159199
],
160200
"serviceAccountName" => "#{system}-sa"
@@ -166,6 +206,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
166206
}
167207
}
168208
}
209+
|> IO.inspect(label: "Deployment")
169210
end
170211

171212
defp build_affinity(system, app_name) do
@@ -421,33 +462,22 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
421462

422463
defp maybe_put_volumes(spec, %{"volumes" => volumes}) do
423464
volumes =
424-
volumes ++
425-
[
426-
%{
427-
"name" => "certs",
428-
"secret" => %{"secretName" => "tls-certs", "optional" => true}
429-
}
430-
]
465+
volumes ++ @default_volumes |> List.flatten() |> Enum.uniq(&(&1["name"]))
431466

432467
Map.merge(spec, %{"volumes" => volumes})
433468
end
434469

435470
defp maybe_put_volumes(spec, _) do
436-
Map.put(spec, "volumes", [
437-
%{
438-
"name" => "certs",
439-
"secret" => %{"secretName" => "tls-certs", "optional" => true}
440-
}
441-
])
471+
Map.put(spec, "volumes", @default_volumes)
442472
end
443473

444474
defp maybe_put_volume_mounts_to_host_container(spec, %{"volumeMounts" => volumeMounts}) do
445-
volumeMounts = volumeMounts ++ [%{"name" => "certs", "mountPath" => "/app/certs"}]
475+
volumeMounts = volumeMounts ++ @default_volume_mounts |> List.flatten() |> Enum.uniq(&(&1["name"]))
446476
Map.merge(spec, %{"volumeMounts" => volumeMounts})
447477
end
448478

449479
defp maybe_put_volume_mounts_to_host_container(spec, _) do
450-
Map.put(spec, "volumeMounts", [%{"name" => "certs", "mountPath" => "/app/certs"}])
480+
Map.put(spec, "volumeMounts", @default_volume_mounts)
451481
end
452482

453483
defp maybe_warn_wrong_volumes(params, host_params) do

spawn_operator/spawn_operator/lib/spawn_operator/k8s/system/secret/actor_system_secret.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
4242
defp get_storage_options(_system, _ns, params) do
4343
statestore = String.downcase(Map.get(params, "type", "native")) |> Base.encode64()
4444
pool_params = Map.get(params, "pool", %{})
45-
pool_size = Map.get(pool_params, "size", "10") |> Base.encode64()
45+
pool_size = "#{Map.get(pool_params, "size", 10)}" |> Base.encode64()
4646
statestore_credentials_secret_ref = Map.get(params, "credentialsSecretRef", "none")
4747
statestore_ssl = "#{Map.get(params, "ssl", "false")}" |> Base.encode64()
4848
statestore_ssl_verify = "#{Map.get(params, "ssl_verify", "false")}" |> Base.encode64()

spawn_operator/spawn_operator/lib/spawn_operator/k8s_conn.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule SpawnOperator.K8sConn do
1111

1212
@spec get(atom()) :: K8s.Conn.t()
1313
def get(:dev) do
14-
{:ok, conn} = K8s.Conn.from_file("~/.kube/config", context: "k3d-eigr-spawn")
14+
{:ok, conn} = K8s.Conn.from_file("~/.kube/config", context: "k3d-k3d-eigr-spawn")
1515
struct!(conn, insecure_skip_tls_verify: true)
1616
end
1717

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,183 @@
11
defmodule SpawnOperator.Versions.Api.V1.ActorHost do
2-
use Bonny.API.Version
2+
@moduledoc """
3+
ActorHost CRD v1 version.
4+
"""
5+
use Bonny.API.Version, hub: true
6+
7+
import YamlElixir.Sigil
38

49
@impl true
510
def manifest() do
6-
defaults()
7-
|> struct!(
11+
struct!(
12+
defaults(),
813
name: "v1",
9-
storage: true
14+
schema: ~y"""
15+
:openAPIV3Schema:
16+
:type: object
17+
:description: |
18+
Defines an ActorHost application. Example:
19+
20+
21+
---
22+
apiVersion: spawn-eigr.io/v1
23+
kind: ActorHost
24+
metadata:
25+
name: my-java-app
26+
spec:
27+
host:
28+
image: ghcr.io/eigr/spawn-springboot-examples:latest
29+
sdk: java
30+
ports:
31+
- containerPort: 80
32+
33+
:required: ["spec"]
34+
:properties:
35+
:spec:
36+
type: object
37+
properties:
38+
autoscaler:
39+
type: object
40+
properties:
41+
min:
42+
type: integer
43+
max:
44+
type: integer
45+
averageCpuUtilizationPercentage:
46+
type: integer
47+
averageMemoryUtilizationValue:
48+
type: integer
49+
affinity:
50+
type: object
51+
replicas:
52+
type: integer
53+
topology:
54+
type: object
55+
properties:
56+
nodeSelector:
57+
type: object
58+
additionalProperties:
59+
type: string
60+
tolerations:
61+
type: array
62+
items:
63+
type: object
64+
properties:
65+
key:
66+
type: string
67+
operator:
68+
type: string
69+
effect:
70+
type: string
71+
host:
72+
type: object
73+
required:
74+
- image
75+
properties:
76+
image:
77+
type: string
78+
embedded:
79+
type: boolean
80+
sdk:
81+
type: string
82+
enum: ["dart", "elixir", "go", "java", "python", "rust", "springboot", "nodejs"]
83+
ports:
84+
type: array
85+
items:
86+
type: object
87+
properties:
88+
name:
89+
type: string
90+
containerPort:
91+
type: integer
92+
taskActors:
93+
type: array
94+
items:
95+
type: object
96+
properties:
97+
actorName:
98+
type: string
99+
workerPool:
100+
type: object
101+
properties:
102+
min:
103+
type: integer
104+
max:
105+
type: integer
106+
maxConcurrency:
107+
type: integer
108+
bootTimeout:
109+
type: integer
110+
callTimeout:
111+
type: integer
112+
oneOff:
113+
type: string
114+
enum: ["true", "false"]
115+
idleShutdownAfter:
116+
type: integer
117+
topology:
118+
type: object
119+
properties:
120+
nodeSelector:
121+
type: object
122+
additionalProperties:
123+
type: string
124+
tolerations:
125+
type: array
126+
items:
127+
type: object
128+
properties:
129+
key:
130+
type: string
131+
operator:
132+
type: string
133+
effect:
134+
type: string
135+
env:
136+
type: array
137+
items:
138+
type: object
139+
properties:
140+
name:
141+
type: string
142+
value:
143+
type: string
144+
valueFrom:
145+
type: object
146+
properties:
147+
fieldRef:
148+
type: object
149+
properties:
150+
fieldPath:
151+
type: string
152+
"""a,
153+
additionalPrinterColumns: [
154+
%{
155+
name: "Host SDK",
156+
type: "string",
157+
description: "SDK used by the ActorHost",
158+
jsonPath: ".spec.host.sdk"
159+
},
160+
%{
161+
name: "Image",
162+
type: "string",
163+
description: "Docker image used for the ActorHost",
164+
jsonPath: ".spec.host.image"
165+
},
166+
%{
167+
name: "Min Replicas",
168+
type: "integer",
169+
description: "Minimum number of replicas for the ActorHost",
170+
jsonPath: ".spec.autoscaler.min"
171+
},
172+
%{
173+
name: "Max Replicas",
174+
type: "integer",
175+
description: "Maximum number of replicas for the ActorHost",
176+
jsonPath: ".spec.autoscaler.max"
177+
}
178+
]
10179
)
11180
|> add_observed_generation_status()
181+
|> add_conditions()
12182
end
13183
end

0 commit comments

Comments
 (0)