Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/strip-j2-jinja: implement rstrip for jinja2 input #916

Merged
merged 3 commits into from
Jan 13, 2023

Conversation

jkrzemin
Copy link
Contributor

@jkrzemin jkrzemin commented Dec 31, 2022

Added options "strip_postfix" and "stripped_postfix" to jinja2 input. This allows to remove output files extensions which is often the case for jinja2 template files (.j2).

Stripping is disabled by default and default value to strip is ".j2".

Closes issue #805

Proposed Changes

  • add option "strip_postfix" to jinja2 input
  • add option "stripped_postfix" to jinja2 input
  • optional removal of file postfixes (i.e. extensions) on output files

Added options "strip_postfix" and "stripped_postfix" to jinja2 input.
This allows to remove output files extensions which is often the case
for jinja2 template files (.j2).

Stripping is disabled by default and default value to strip is ".j2".
@beddari
Copy link

beddari commented Jan 6, 2023

Would it improve clarity a bit to change the variable names used here?

suffix_remove: true
suffix_list:
  - .j2

Additionally, we would like this feature to become a new default for the jinja2 input type, I added a comment about that to #805

@jkrzemin
Copy link
Contributor Author

jkrzemin commented Jan 8, 2023

Fair point, this naming makes more sense. I'll update the PR tomorrow. Like we discussed on slack, I don't think it should be a default since it is a breaking change and quite a few can have workarounds for that. I think that the best approach would be to make it opt-in for now and a default in future.

@ademariag ademariag requested a review from ramaro January 10, 2023 17:17
@ademariag
Copy link
Contributor

IMHO passing the list of suffix to strip might overcomplicate the problem, but curious to see what @ramaro thinks.

I'd stick to expect, if the flag is enabled, that all files have a .j2 extension, and remove it present.
what happens if the file doesn't have a j2 extension? we silently ignore it? we don't process it?

the one benefit of expecting the .j2 extension is that it would be easier to exclude from tests and linting files that are templates, which at the moment is not possible.

@jkrzemin
Copy link
Contributor Author

Currently if file doesn't have an expected suffix (.j2 is a default, can be overridden) it will simply pass it over to rendering.

I don't think that skipping files without suffix is a good idea - you still have to provide them explicitly in compile step so I think that we can assume that if file ends up here, it should be rendered.

@ademariag
Copy link
Contributor

you still have to provide them explicitly in compile step so I think that we can assume that if file ends up here, it should be rendered.

Kapitan also supports passing a directory, in which case you won't have explicitly all files declared in the inventory.

But yes I also think we can just make it compile anyway

Rename parameters for suffix removal in jinja2 compile step.

Rename:
strip_postfix -> suffix_remove
stripped_postfix -> suffix_stripped
@ramaro ramaro merged commit 3cda228 into kapicorp:master Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants