kapicorp / kapitan

Generic templated configuration management for Kubernetes, Terraform and other things
https://kapitan.dev
Apache License 2.0
1.83k stars 199 forks source link

Ability to strip .j2 extension when performing jinja2 compilation and potentially fully rename #805

Open KostasKgr opened 2 years ago

KostasKgr commented 2 years ago

Describe the feature Ability to strip .j2 extension when performing jinja2 compilation. It is useful to have .j2 extension on files for at least two reasons:

If a file path is specified for output_path then this gets interpreted as a folder name. https://kapitan.dev/compile/#specifying-inputs-and-outputs

Perhaps general renaming would cover more use cases, such as compiling a template to multiple outputs in the same node or providing a better semantic name to the template.

Raising this after discussing stripping .j2 in kapitan slack channel.

I don't have some good recommendation on how to approach it, as the current interface of compile expects multiple input files and one output directory. Perhaps ansible template module can be used for inspiration: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html

To Reproduce

parameters:
  kapitan:
    compile:
    - output_path: app/my_app1/config.cfg
      input_type: jinja2
      input_paths:
        - templates/generic_python_config.cfg.j2
      input_params:
        name: my_app1
        # ...

Output of the above would be compiled to app/my_app1/config.cfg/generic_python_config.cfg.j2

Expected behavior Able to drop .j2 extension and rename. Ouput would be compiled to app/my_app1/config.cfg

Additional context Using kapicorp/kapitan:v0.30.0-rc.0

beddari commented 1 year ago

Valid problem! I have not seen the slack discussion, but my best idea to solve this would be to simply strip any .j2 extension by default.

That would break any current users wanting to write e.g a example.j2 file to output_path, but that is maybe more of an edge case, and could be fixed by naming the input file example.j2.j2?

beddari commented 1 year ago

The referenced PR implements stripping and so I guess what remains is more a decision about what would be the best default behavior - and again, changing it to strip .j2 by default seems sensible.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 1 year with no activity. Remove the stale label or comment if this issue is still relevant for you. If not, please close it yourself.