github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/site/book/07-effective-customizations/03-generation.md (about) 1 ## Scenario: 2 3 When using template languages I am able to provide conditional statements based 4 on parameter values. This allows me to ask the user for a little bit of 5 information and generate a lot of boilerplate configuration. Some template 6 languages like [Jinja] are very robust and feature rich. 7 8 ## Problems: 9 10 1. Increased usage and additional edge cases make a template a piece of code 11 that requires testing and debugging. 12 1. The interplay between different conditionals and loops is interleaved in the template making it hard to understand what exactly is configuration and what is 13 the logic that alters the configuration. The consumer is left with one choice 14 supply different parameter values, execute the template rendering code and see 15 what happens. 16 1. Templates are generally monolithic, when a change is introduced the package consumers need to either pay the cost of updating or the new consumers pay the 17 cost of having to decipher more optional parameters. 18 19 ## Solutions: 20 21 1. When the generated configuration is simple consider just using a sub-package 22 and running customizations using [single value replacement] techniques. 23 1. When a complex configuration needs to be generated the package author can 24 create a generator function using turing complete languages and debugging tools. Example of such a function is [folder generation]. The output of the function 25 is plain old KRM. 26 27 [folder generation]: https://catalog.kpt.dev/generate-folders/v0.1/ 28 [Jinja]: https://palletsprojects.com/p/jinja/ 29 [single value replacement]: /book/07-effective-customizations/01-single-value-replacement.md