@@ -88,6 +88,13 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
88
88
89
89
@ default_termination_period_seconds 405
90
90
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
+
91
98
@ impl true
92
99
def manifest ( resource , _opts \\ [ ] ) , do: gen_deployment ( resource )
93
100
@@ -102,6 +109,20 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
102
109
} = _resource
103
110
) do
104
111
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
+
105
126
task_actors_config = % { "taskActors" => Map . get ( host_params , "taskActors" , % { } ) }
106
127
topology = Map . get ( params , "topology" , % { } )
107
128
@@ -110,6 +131,36 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
110
131
111
132
maybe_warn_wrong_volumes ( params , host_params )
112
133
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
+
113
164
% {
114
165
"apiVersion" => "apps/v1" ,
115
166
"kind" => "Deployment" ,
@@ -152,37 +203,16 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
152
203
name ,
153
204
host_params ,
154
205
annotations ,
155
- task_actors_config
206
+ task_actors_config ,
207
+ erlang_profile ,
208
+ erlang_mtls_enabled
156
209
) ,
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 ,
181
211
"serviceAccountName" => "#{ system } -sa"
182
212
}
183
213
|> maybe_put_node_selector ( topology )
184
214
|> maybe_put_node_tolerations ( topology )
185
- |> maybe_put_volumes ( params )
215
+ |> maybe_put_volumes ( params , erlang_mtls_enabled )
186
216
|> maybe_set_termination_period ( params )
187
217
}
188
218
}
@@ -237,7 +267,16 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
237
267
}
238
268
end
239
269
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
241
280
actor_host_function_image = Map . get ( host_params , "image" )
242
281
243
282
updated_default_envs =
@@ -248,6 +287,10 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
248
287
"valueFrom" => % {
249
288
"secretKeyRef" => % { "name" => "#{ system } -secret" , "key" => "RELEASE_COOKIE" }
250
289
}
290
+ } ,
291
+ % {
292
+ "name" => "ERL_FLAGS" ,
293
+ "value" => flags
251
294
}
252
295
]
253
296
@@ -293,14 +336,23 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
293
336
"ports" => actor_host_function_ports ,
294
337
"resources" => actor_host_function_resources
295
338
}
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 )
297
340
298
341
[
299
342
host_and_proxy_container
300
343
]
301
344
end
302
345
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
304
356
actor_host_function_image = Map . get ( host_params , "image" )
305
357
306
358
updated_default_envs =
@@ -311,6 +363,10 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
311
363
"valueFrom" => % {
312
364
"secretKeyRef" => % { "name" => "#{ system } -secret" , "key" => "RELEASE_COOKIE" }
313
365
}
366
+ } ,
367
+ % {
368
+ "name" => "ERL_FLAGS" ,
369
+ "value" => flags
314
370
}
315
371
]
316
372
@@ -380,7 +436,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
380
436
}
381
437
]
382
438
}
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 )
384
440
385
441
host_container =
386
442
% {
@@ -390,7 +446,7 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
390
446
"resources" => actor_host_function_resources
391
447
}
392
448
|> 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 )
394
450
395
451
[
396
452
proxy_container ,
@@ -441,61 +497,99 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
441
497
Map . put ( spec , "terminationGracePeriodSeconds" , @ default_termination_period_seconds )
442
498
end
443
499
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 )
448
510
|> List . flatten ( )
449
- |> Enum . uniq ( & & 1 [ "name" ] )
511
+ |> Enum . uniq_by ( & & 1 [ "name" ] )
450
512
451
- Map . merge ( spec , % { "volumes" => volumes } )
513
+ if all_volumes == [ ] , do: spec , else: Map . put ( spec , "volumes" , all_volumes )
452
514
end
453
515
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
459
523
460
- Map . put ( spec , "volumes" , volumes )
524
+ if default_volumes == [ ] , do: spec , else: Map . put ( spec , "volumes" , default_volumes )
461
525
end
462
526
463
527
defp maybe_put_volume_mounts_to_host_container (
464
528
spec ,
465
- % { "volumeMounts" => volumeMounts } ,
466
- :actorhost
529
+ % { "volumeMounts" => volume_mounts } ,
530
+ :actorhost ,
531
+ erlang_mtls_enabled
467
532
) 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" ] )
470
544
471
- Map . merge ( spec , % { "volumeMounts" => volumeMounts } )
545
+ if all_volume_mounts == [ ] , do: spec , else: Map . put ( spec , "volumeMounts" , all_volume_mounts )
472
546
end
473
547
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 )
476
559
end
477
560
478
561
defp maybe_put_volume_mounts_to_host_container (
479
562
spec ,
480
- % { "volumeMounts" => volumeMounts } ,
481
- :sidecar
563
+ % { "volumeMounts" => volume_mounts } ,
564
+ :sidecar ,
565
+ erlang_mtls_enabled
482
566
) 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 )
486
576
|> List . flatten ( )
487
- |> Enum . uniq ( & & 1 [ "name" ] )
577
+ |> Enum . uniq_by ( & & 1 [ "name" ] )
488
578
489
- Map . merge ( spec , % { "volumeMounts" => volumeMounts } )
579
+ if all_volume_mounts == [ ] , do: spec , else: Map . put ( spec , "volumeMounts" , all_volume_mounts )
490
580
end
491
581
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
497
589
498
- Map . put ( spec , "volumeMounts" , volumeMounts )
590
+ if default_volume_mounts == [ ] ,
591
+ do: spec ,
592
+ else: Map . put ( spec , "volumeMounts" , default_volume_mounts )
499
593
end
500
594
501
595
defp maybe_warn_wrong_volumes ( params , host_params ) do
0 commit comments