-
Notifications
You must be signed in to change notification settings - Fork 85
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(map): enable import of mapdata
from outside the formula
#230
base: master
Are you sure you want to change the base?
feat(map): enable import of mapdata
from outside the formula
#230
Conversation
b10cada
to
8797eba
Compare
mapdata
from outside the formulamapdata
from outside the formula
8797eba
to
985b2b7
Compare
I see only 2 differences between
As an example, here is my setup: /srv/salt/foo/test.sls# -*- mode: salt; coding: utf-8 -*-
# vim: ft=sls
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/test-context.jinja" import context as context_with_context_import with context %}
{%- from tplroot ~ "/test-context.jinja" import context as context_without_context_import without context %}
test-context-content-with-context-import:
file.managed:
- name: /tmp/context-with-context.txt
- source: salt://foo/serialize_yaml.jinja
- template: jinja
- context:
value: {{ context_with_context_import | json }}
test-context-content-without-context-import:
file.managed:
- name: /tmp/context-without-context.txt
- source: salt://foo/serialize_yaml.jinja
- template: jinja
- context:
value: {{ context_without_context_import | json }}
test-context-diff-between-with-context-and-without:
cmd.run:
- name: 'diff -u /tmp/context-with-context.txt /tmp/context-without-context.txt' /srv/salt/foo/test-context.jinja{%- set context = show_full_context() %} /srv/salt/foo/serialize_yaml.jinja---
{#- use salt.slsutil.serialize to avoid encoding errors on some platforms #}
{{ salt["slsutil.serialize"](
"yaml",
value,
default_flow_style=False,
allow_unicode=True,
)
| regex_replace("^\s+'$", "'", multiline=True)
| trim
}}
... Log of salt-call -l debug state.apply foo.test
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. thanks @baby-gnu
Thanks @noelmcloughlin for the review. I see no formula using 🤔 I see some |
`tplroot` can't be set correctly when the import: - is done from another top directory than the formula directory - the import is done `with context` In this case, the `tpldir` is set to the directory of the importer `.sls` file instead of the `.jinja` imported one. We force the `without context` which permits to directly use `tpldir` as the `tplroot` which is the directory of the imported file. BREAKING CHANGE: `map.jinja` import must use `without context` BREAKING CHANGE: `libmapstack.jinja` import must use `without context` BREAKING CHANGE: `libmatchers.jinja` import must use `without context`
f5b37d2
to
1555e42
Compare
I think this would break our workflow. We have many formulas and we want to use a single version of tofs for all of them rather than including the file in all of the formulas. This significantly reduces duplication. The directory tree is something like:
# cat ssh/client.sls
{%- from "_tofs/libtofs.jinja" import files_switch with context %}
{%- from "_tofs/map.jinja" import mapdata with context %}
ssh_config:
file.managed:
- name: {{ mapdata['filename'] }}
- source: {{ files_switch(
["/etc/ssh/ssh_config.tmpl"],
lookup="ssh_config",
)
}}
- user: root
- group: wheel
- mode: "0644"
- template: jinja By importing with context we can keep the tofs files in a different directory and it still correctly finds the tplroot of the formula. I haven't tested this change, but if it forces imports "without context" then I believe our setup will break. The tofs files are supposed to be considered "library" files, so I think it would be silly to make them function based on their location rather than the location of the file doing the import. Alternatively, someone could just supply a "without context" if they want that (incredibly weird) functionality. |
PR progress checklist (to be filled in by reviewers)
What type of PR is this?
Primary type
[build]
Changes related to the build system[chore]
Changes to the build process or auxiliary tools and libraries such as documentation generation[ci]
Changes to the continuous integration configuration[feat]
A new feature[fix]
A bug fix[perf]
A code change that improves performance[refactor]
A code change that neither fixes a bug nor adds a feature[revert]
A change used to revert a previous commit[style]
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)Secondary type
[docs]
Documentation changes[test]
Adding missing or correcting existing testsDoes this PR introduce a
BREAKING CHANGE
?Yes.
BREAKING CHANGE:
map.jinja
import must usewithout context
BREAKING CHANGE:
libmapstack.jinja
import must usewithout context
BREAKING CHANGE:
libmatchers.jinja
import must usewithout context
Related issues and/or pull requests
saltstack-formulas/apache-formula#295
saltstack-formulas/cert-formula#37
Describe the changes you're proposing
tplroot
can't be set correctly when the import:with context
In this case, the
tpldir
is set to the directory of the importer.sls
file instead of the.jinja
imported one.We force the
without context
which permits to directly usetpldir
as thetplroot
which is the directory of the imported file.Pillar / config required to test the proposed changes
Debug log showing how the proposed changes work
Documentation checklist
README
(e.g.Available states
).pillar.example
.Testing checklist
state_top
).Additional context