55
66
77import shlex
8- from typing import Callable , Iterator , Tuple
8+ from typing import Callable , Iterator , Tuple , Dict
99
1010import doit # type: ignore
1111
1212from buildchain import constants
13+ from buildchain import targets
1314from buildchain import types
1415from buildchain import utils
1516
1617
17- def get_task_information () -> types .TaskDict :
18- """Retrieve all the task information from codegen"""
19- result : types .TaskDict = {
20- "actions" : [],
21- "task_dep" : [],
22- "file_dep" : [],
23- }
24- for task_fun in CODEGEN :
25- task = task_fun ()
26- for key , value in result .items ():
27- value .extend (task .get (key , []))
28-
29- return result
30-
31-
3218def task_codegen () -> Iterator [types .TaskDict ]:
3319 """Run the code generation tools."""
3420 for create_codegen_task in CODEGEN :
@@ -333,6 +319,65 @@ def codegen_chart_cert_manager() -> types.TaskDict:
333319 }
334320
335321
322+ def task_get_codegen_kustomize_crl_operator () -> types .TaskDict :
323+ """Generate the kustomize manifests output for the CRL Operator."""
324+ kustomize_dir = constants .ROOT / "kustomizes/crl-operator"
325+
326+ cmd = f"kustomize build { kustomize_dir } "
327+
328+ return {
329+ "doc" : task_get_codegen_kustomize_crl_operator .__doc__ ,
330+ "actions" : [doit .action .CmdAction (cmd , cwd = constants .ROOT , save_out = "stdout" )],
331+ "file_dep" : list (utils .git_ls (kustomize_dir )),
332+ "task_dep" : ["check_for:kustomize" ],
333+ }
334+
335+
336+ def task_transform_codegen_kustomize_crl_operator () -> types .TaskDict :
337+ """Transform the kustomize manifests output for the CRL Operator."""
338+
339+ def _transform (stdout : str ) -> Dict [str , str ]:
340+ """Transform the kustomize output."""
341+ # Note: We have to replace the namespace 'crl-operator-system' by
342+ # 'metalk8s-certs' as kustomize does not allow easily to patch every
343+ # occurrence in "custom resources fields" like Certificate dnsNames.
344+ return {
345+ "output" : stdout .strip ().replace ("crl-operator-system" , "metalk8s-certs" )
346+ }
347+
348+ return {
349+ "doc" : task_transform_codegen_kustomize_crl_operator .__doc__ ,
350+ "actions" : [_transform ],
351+ "task_dep" : ["get_codegen_kustomize_crl_operator" ],
352+ "getargs" : {
353+ "stdout" : ("get_codegen_kustomize_crl_operator" , "stdout" ),
354+ },
355+ }
356+
357+
358+ def codegen_kustomize_crl_operator () -> types .TaskDict :
359+ """Generate the SLS file for the CRL Operator."""
360+ target_sls = constants .ROOT / "salt/metalk8s/addons/crl-operator/deployed/chart.sls"
361+ template_file = constants .ROOT / "kustomizes/template.sls.in"
362+
363+ tpl_task = targets .TemplateFile (
364+ task_name = "kustomize_crl-operator" ,
365+ source = template_file ,
366+ destination = target_sls ,
367+ )
368+ tpl_task_dict = tpl_task .task
369+ tpl_task_dict .update (
370+ {
371+ "title" : utils .title_with_subtask_name ("CODEGEN" ),
372+ "task_dep" : ["transform_codegen_kustomize_crl_operator" ],
373+ "getargs" : {
374+ "Manifests" : ("transform_codegen_kustomize_crl_operator" , "output" ),
375+ },
376+ }
377+ )
378+ return tpl_task_dict
379+
380+
336381# List of available code generation tasks.
337382CODEGEN : Tuple [Callable [[], types .TaskDict ], ...] = (
338383 codegen_storage_operator ,
@@ -345,6 +390,7 @@ def codegen_chart_cert_manager() -> types.TaskDict:
345390 codegen_chart_prometheus_adapter ,
346391 codegen_chart_thanos ,
347392 codegen_chart_cert_manager ,
393+ codegen_kustomize_crl_operator ,
348394)
349395
350396
0 commit comments