@@ -88,6 +88,13 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
8888
8989 @ default_termination_period_seconds 405
9090
91+ @ erlang_profiles % {
92+ insecure_erl_flags:
93+ "+C multi_time_warp -mode embedded +sbwt none +sbwtdcpu none +sbwtdio none" ,
94+ tls_erl_flags:
95+ " -proto_dist inet_tls -ssl_dist_optfile /app/mtls.ssl.conf +C multi_time_warp -mode embedded +sbwt none +sbwtdcpu none +sbwtdio none"
96+ }
97+
9198 @ impl true
9299 def manifest ( resource , _opts \\ [ ] ) , do: gen_deployment ( resource )
93100
@@ -102,6 +109,20 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
102109 } = _resource
103110 ) do
104111 host_params = Map . get ( params , "host" )
112+
113+ cluster =
114+ Map . get ( params , "cluster" , % { "features" => % { "erlangMtls" => % { "enabled" => false } } } )
115+
116+ erlang_mtls_enabled =
117+ Map . get ( cluster , "features" , % { } )
118+ |> Map . get ( "erlangMtls" , % { } )
119+ |> Map . get ( "enabled" , false )
120+
121+ erlang_profile =
122+ if erlang_mtls_enabled ,
123+ do: @ erlang_profiles . tls_erl_flags ,
124+ else: @ erlang_profiles . insecure_erl_flags
125+
105126 task_actors_config = % { "taskActors" => Map . get ( host_params , "taskActors" , % { } ) }
106127 topology = Map . get ( params , "topology" , % { } )
107128
@@ -110,6 +131,36 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
110131
111132 maybe_warn_wrong_volumes ( params , host_params )
112133
134+ init_containers =
135+ if erlang_mtls_enabled do
136+ [
137+ % {
138+ "name" => "init-certificates" ,
139+ "image" => "#{ annotations . proxy_init_container_image_tag } " ,
140+ "args" => [
141+ "--environment" ,
142+ :prod ,
143+ "--secret" ,
144+ "tls-certs" ,
145+ "--namespace" ,
146+ "#{ system } " ,
147+ "--service" ,
148+ "#{ system } " ,
149+ "--to" ,
150+ "#{ system } "
151+ ] ,
152+ "env" => [
153+ % {
154+ "name" => "RELEASE_DISTRIBUTION" ,
155+ "value" => "none"
156+ }
157+ ]
158+ }
159+ ]
160+ else
161+ [ ]
162+ end
163+
113164 % {
114165 "apiVersion" => "apps/v1" ,
115166 "kind" => "Deployment" ,
@@ -152,37 +203,16 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
152203 name ,
153204 host_params ,
154205 annotations ,
155- task_actors_config
206+ task_actors_config ,
207+ erlang_profile ,
208+ erlang_mtls_enabled
156209 ) ,
157- "initContainers" => [
158- % {
159- "name" => "init-certificates" ,
160- "image" => "#{ annotations . proxy_init_container_image_tag } " ,
161- "args" => [
162- "--environment" ,
163- :prod ,
164- "--secret" ,
165- "tls-certs" ,
166- "--namespace" ,
167- "#{ system } " ,
168- "--service" ,
169- "#{ system } " ,
170- "--to" ,
171- "#{ system } "
172- ] ,
173- "env" => [
174- % {
175- "name" => "RELEASE_DISTRIBUTION" ,
176- "value" => "none"
177- }
178- ]
179- }
180- ] ,
210+ "initContainers" => init_containers ,
181211 "serviceAccountName" => "#{ system } -sa"
182212 }
183213 |> maybe_put_node_selector ( topology )
184214 |> maybe_put_node_tolerations ( topology )
185- |> maybe_put_volumes ( params )
215+ |> maybe_put_volumes ( params , erlang_mtls_enabled )
186216 |> maybe_set_termination_period ( params )
187217 }
188218 }
@@ -237,7 +267,16 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
237267 }
238268 end
239269
240- defp get_containers ( true , system , name , host_params , annotations , task_actors_config ) do
270+ defp get_containers (
271+ true ,
272+ system ,
273+ name ,
274+ host_params ,
275+ annotations ,
276+ task_actors_config ,
277+ flags ,
278+ erlang_mtls_enabled
279+ ) do
241280 actor_host_function_image = Map . get ( host_params , "image" )
242281
243282 updated_default_envs =
@@ -248,6 +287,10 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
248287 "valueFrom" => % {
249288 "secretKeyRef" => % { "name" => "#{ system } -secret" , "key" => "RELEASE_COOKIE" }
250289 }
290+ } ,
291+ % {
292+ "name" => "ERL_FLAGS" ,
293+ "value" => flags
251294 }
252295 ]
253296
@@ -293,14 +336,23 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
293336 "ports" => actor_host_function_ports ,
294337 "resources" => actor_host_function_resources
295338 }
296- |> maybe_put_volume_mounts_to_host_container ( host_params , :actorhost )
339+ |> maybe_put_volume_mounts_to_host_container ( host_params , :actorhost , erlang_mtls_enabled )
297340
298341 [
299342 host_and_proxy_container
300343 ]
301344 end
302345
303- defp get_containers ( false , system , name , host_params , annotations , task_actors_config ) do
346+ defp get_containers (
347+ false ,
348+ system ,
349+ name ,
350+ host_params ,
351+ annotations ,
352+ task_actors_config ,
353+ flags ,
354+ erlang_mtls_enabled
355+ ) do
304356 actor_host_function_image = Map . get ( host_params , "image" )
305357
306358 updated_default_envs =
@@ -311,6 +363,10 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
311363 "valueFrom" => % {
312364 "secretKeyRef" => % { "name" => "#{ system } -secret" , "key" => "RELEASE_COOKIE" }
313365 }
366+ } ,
367+ % {
368+ "name" => "ERL_FLAGS" ,
369+ "value" => flags
314370 }
315371 ]
316372
@@ -380,7 +436,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
380436 }
381437 ]
382438 }
383- |> maybe_put_volume_mounts_to_host_container ( host_params , :sidecar )
439+ |> maybe_put_volume_mounts_to_host_container ( host_params , :sidecar , erlang_mtls_enabled )
384440
385441 host_container =
386442 % {
@@ -390,7 +446,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
390446 "resources" => actor_host_function_resources
391447 }
392448 |> maybe_put_ports_to_host_container ( host_params )
393- |> maybe_put_volume_mounts_to_host_container ( host_params , :actorhost )
449+ |> maybe_put_volume_mounts_to_host_container ( host_params , :actorhost , erlang_mtls_enabled )
394450
395451 [
396452 proxy_container ,
@@ -441,61 +497,99 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
441497 Map . put ( spec , "terminationGracePeriodSeconds" , @ default_termination_period_seconds )
442498 end
443499
444- defp maybe_put_volumes ( spec , % { "volumes" => volumes } = _params ) do
445- volumes =
446- ( volumes ++
447- @ default_volumes )
500+ defp maybe_put_volumes ( spec , % { "volumes" => volumes } = _params , erlang_mtls_enabled ) do
501+ default_volumes =
502+ if erlang_mtls_enabled do
503+ @ default_volumes
504+ else
505+ Enum . reject ( @ default_volumes , & ( & 1 [ "name" ] == "certs" ) )
506+ end
507+
508+ all_volumes =
509+ ( volumes ++ default_volumes )
448510 |> List . flatten ( )
449- |> Enum . uniq ( & & 1 [ "name" ] )
511+ |> Enum . uniq_by ( & & 1 [ "name" ] )
450512
451- Map . merge ( spec , % { "volumes" => volumes } )
513+ if all_volumes == [ ] , do: spec , else: Map . put ( spec , "volumes" , all_volumes )
452514 end
453515
454- defp maybe_put_volumes ( spec , _params ) do
455- volumes =
456- @ default_volumes
457- |> List . flatten ( )
458- |> Enum . uniq ( & & 1 [ "name" ] )
516+ defp maybe_put_volumes ( spec , _params , erlang_mtls_enabled ) do
517+ default_volumes =
518+ if erlang_mtls_enabled do
519+ @ default_volumes
520+ else
521+ Enum . reject ( @ default_volumes , & ( & 1 [ "name" ] == "certs" ) )
522+ end
459523
460- Map . put ( spec , "volumes" , volumes )
524+ if default_volumes == [ ] , do: spec , else: Map . put ( spec , "volumes" , default_volumes )
461525 end
462526
463527 defp maybe_put_volume_mounts_to_host_container (
464528 spec ,
465- % { "volumeMounts" => volumeMounts } ,
466- :actorhost
529+ % { "volumeMounts" => volume_mounts } ,
530+ :actorhost ,
531+ erlang_mtls_enabled
467532 ) do
468- volumeMounts =
469- ( volumeMounts ++ @ default_volume_mounts ) |> List . flatten ( ) |> Enum . uniq ( & & 1 [ "name" ] )
533+ default_volume_mounts =
534+ if erlang_mtls_enabled do
535+ @ default_volume_mounts
536+ else
537+ Enum . reject ( @ default_volume_mounts , & ( & 1 [ "name" ] == "certs" ) )
538+ end
539+
540+ all_volume_mounts =
541+ ( volume_mounts ++ default_volume_mounts )
542+ |> List . flatten ( )
543+ |> Enum . uniq_by ( & & 1 [ "name" ] )
470544
471- Map . merge ( spec , % { "volumeMounts" => volumeMounts } )
545+ if all_volume_mounts == [ ] , do: spec , else: Map . put ( spec , "volumeMounts" , all_volume_mounts )
472546 end
473547
474- defp maybe_put_volume_mounts_to_host_container ( spec , _ , :actorhost ) do
475- Map . put ( spec , "volumeMounts" , @ default_volume_mounts )
548+ defp maybe_put_volume_mounts_to_host_container ( spec , _ , :actorhost , erlang_mtls_enabled ) do
549+ default_volume_mounts =
550+ if erlang_mtls_enabled do
551+ @ default_volume_mounts
552+ else
553+ Enum . reject ( @ default_volume_mounts , & ( & 1 [ "name" ] == "certs" ) )
554+ end
555+
556+ if default_volume_mounts == [ ] ,
557+ do: spec ,
558+ else: Map . put ( spec , "volumeMounts" , default_volume_mounts )
476559 end
477560
478561 defp maybe_put_volume_mounts_to_host_container (
479562 spec ,
480- % { "volumeMounts" => volumeMounts } ,
481- :sidecar
563+ % { "volumeMounts" => volume_mounts } ,
564+ :sidecar ,
565+ erlang_mtls_enabled
482566 ) do
483- volumeMounts =
484- volumeMounts
485- |> Kernel . ++ ( @ default_volume_mounts )
567+ default_volume_mounts =
568+ if erlang_mtls_enabled do
569+ @ default_volume_mounts
570+ else
571+ Enum . reject ( @ default_volume_mounts , & ( & 1 [ "name" ] == "certs" ) )
572+ end
573+
574+ all_volume_mounts =
575+ ( volume_mounts ++ default_volume_mounts )
486576 |> List . flatten ( )
487- |> Enum . uniq ( & & 1 [ "name" ] )
577+ |> Enum . uniq_by ( & & 1 [ "name" ] )
488578
489- Map . merge ( spec , % { "volumeMounts" => volumeMounts } )
579+ if all_volume_mounts == [ ] , do: spec , else: Map . put ( spec , "volumeMounts" , all_volume_mounts )
490580 end
491581
492- defp maybe_put_volume_mounts_to_host_container ( spec , _ , :sidecar ) do
493- volumeMounts =
494- @ default_volume_mounts
495- |> List . flatten ( )
496- |> Enum . uniq ( & & 1 [ "name" ] )
582+ defp maybe_put_volume_mounts_to_host_container ( spec , _ , :sidecar , erlang_mtls_enabled ) do
583+ default_volume_mounts =
584+ if erlang_mtls_enabled do
585+ @ default_volume_mounts
586+ else
587+ Enum . reject ( @ default_volume_mounts , & ( & 1 [ "name" ] == "certs" ) )
588+ end
497589
498- Map . put ( spec , "volumeMounts" , volumeMounts )
590+ if default_volume_mounts == [ ] ,
591+ do: spec ,
592+ else: Map . put ( spec , "volumeMounts" , default_volume_mounts )
499593 end
500594
501595 defp maybe_warn_wrong_volumes ( params , host_params ) do
0 commit comments