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

feature(tofs): lookup files directory in “tpldir” hierarchy #37

Conversation

baby-gnu
Copy link
Contributor

Without user configuration, the “libtofs.jinja” lookup the “files”
directory under “tplroot” with is the base directory of the current
formula unless the “v1_path_prefix” is set.

Now, we lookup the directory in each sub-directory from the
sub-directory of the current SLS (“tpldir”) to the top level directory
of the formula (“tplroot”).

This permit to support natively the multi-components formula.

@baby-gnu
Copy link
Contributor Author

This result in the following

       networkd:
         file.recurse:
           - name: /etc/systemd/network
           - user: root
           - group: root
           - template: jinja
           - source: 
             - salt://systemd/networkd/files/any/path/can/be/used/here/network
             - salt://systemd/networkd/files/salt-formula.ci.local/network
             - salt://systemd/networkd/files/Ubuntu-18.04/network
             - salt://systemd/networkd/files/Ubuntu/network
             - salt://systemd/networkd/files/Debian/network
             - salt://systemd/networkd/files/default/network
             - salt://systemd/files/any/path/can/be/used/here/network
             - salt://systemd/files/salt-formula.ci.local/network
             - salt://systemd/files/Ubuntu-18.04/network
             - salt://systemd/files/Ubuntu/network
             - salt://systemd/files/Debian/network
             - salt://systemd/files/default/network
           - clean: True
           - dir_mode: 755
           - file_mode: 644
           - include_empty: True
           - listen_in:
             - service: networkd

Without user configuration, the “libtofs.jinja” lookup the “files”
directory under “tplroot” with is the base directory of the current
formula unless the “v1_path_prefix” is set.

Now, we lookup the directory in each sub-directory from the
sub-directory of the current SLS (“tpldir”) to the top level directory
of the formula (“tplroot”).

This permit to support natively the multi-components formula.
@aboe76
Copy link
Member

aboe76 commented May 20, 2019

@baby-gnu shall I merge first the other PR, before this one?

@aboe76 aboe76 requested a review from myii May 20, 2019 20:48
@baby-gnu
Copy link
Contributor Author

@aboe76 if I understood correctly, @myii asked to do this one first.

@myii
Copy link
Member

myii commented May 21, 2019

@baby-gnu Sorry for the delay, I'll be checking this PR shortly. @aboe76 As laid out here, the plan is to benefit from the improvement in this formula and then "backport" it to the template-formula.

Copy link
Member

@myii myii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent PR, approved really. The requested changes are only aesthetic.


For example, the following ``formula.component.config`` SLS:

.. code-block::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. code-block::
.. code-block:: sls


.. code-block::

{%- from "formula/libtofs.jinja" import files_switch with context -%}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{%- from "formula/libtofs.jinja" import files_switch with context -%}
{%- from "formula/libtofs.jinja" import files_switch with context %}

)
}}

will be rendered on a ``Debian`` named ``salt-formula.ci.local`` as:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
will be rendered on a ``Debian`` named ``salt-formula.ci.local`` as:
will be rendered on a ``Debian`` minion named ``salt-formula.ci.local`` as:


will be rendered on a ``Debian`` named ``salt-formula.ci.local`` as:

.. code-block::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. code-block::
.. code-block:: sls

.. code-block::

formula configuration file:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@myii
Copy link
Member

myii commented May 21, 2019

@baby-gnu One further question: what about removing the if block for v1_path_prefix? It's no longer used in the formula, or anywhere else actually.

To be clear, I mean removing v1_path_prefix completely.

@myii
Copy link
Member

myii commented May 21, 2019

@baby-gnu @aboe76 Another issue that we need to finalise. When this functionality was first produced in saltstack-formulas/template-formula#86, it produced the source list in the current order, e.g.:

    - source:
      - salt://systemd/files/ABC/network
      - salt://systemd/files/Debian/network
      - salt://systemd/files/default/network
      - salt://systemd/networkd/files/ABC/network
      - salt://systemd/networkd/files/Debian/network
      - salt://systemd/networkd/files/default/network

After my saltstack-formulas/template-formula#86 (comment), @baby-gnu reversed the order as requested, to now produce:

    - source:
      - salt://systemd/networkd/files/ABC/network
      - salt://systemd/networkd/files/Debian/network
      - salt://systemd/networkd/files/default/network
      - salt://systemd/files/ABC/network
      - salt://systemd/files/Debian/network
      - salt://systemd/files/default/network

In the same PR, @daks raised concerns about I/O costs (saltstack-formulas/template-formula#86 (comment)).

So my question in, which order is preferable:

  1. sub-component => main component (using |reverse)
  2. main component => sub-component

While number 1 makes sense, in reality those sub-component lookups would be wasted in every formula that doesn't use sub-components (i.e. all of them so far). Another option is to leave this libtofs.jinja customised, so that it works better for systemd-formula. What do you all think?

@aboe76
Copy link
Member

aboe76 commented May 21, 2019

@myii I think if you document comment the changes necessary to switch between:

sub-component => main component (using |reverse)
main component => sub-component

and let the maintainer who implements tofs be the just, if one or the other is necessary.
libtofs.jinja is already a io burden for the sake of flexibility. Having a optimized tofs will be important to other users...

@baby-gnu
Copy link
Contributor Author

@baby-gnu One further question: what about removing the if block for v1_path_prefix? It's no longer used in the formula, or anywhere else actually.

To be clear, I mean removing v1_path_prefix completely.

It can be done but this is a breaking change.

For example, I personnaly always “hook” my personal SLS under the formula namespace (and I think it's the good thing to do), like

gitfs_remotes:
  - https://myserver/my-systemd-config.git
  - https://myserver/systemd-formula.git

my-systemd-config has the same directory tree as systemd-formula (containing only my own files) , so my own repository comes first when salt try to lookup a file under salt://systemd/.

My SLS import looks like this:

{%- from "systemd/map.jinja" import systemd with context %}
{%- from "systemd/libtofs.jinja" import files_switch with context %}

If another user does the same thing as me, she will have troubles if she used the v1_path_prefix in her own SLS.

If everybody agree for this breaking changes, I'll remove it.

Regards.

@baby-gnu
Copy link
Contributor Author

While number 1 makes sense, in reality those sub-component lookups would be wasted in every formula that doesn't use sub-components (i.e. all of them so far). Another option is to leave this libtofs.jinja customised, so that it works better for systemd-formula.

I agree to avoid the automatic sub-component lookup to avoid unnecessary I/O and let it configurable, i.e. close this pull request without merge, but the v1_path_prefix could be better renamed component or just path_prefix

timesyncd:
  file.managed:
    - name: /etc/systemd/timesyncd.conf
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    - source: {{ files_switch(['timesyncd.conf'],
                              lookup='timesyncd',
                              component='timesyncd'
                              )
              }}

The libtofs.jinja should be modified accordingly (and using |join() instead of string concatenation).

@myii
Copy link
Member

myii commented May 24, 2019

@baby-gnu As for this specific PR, I believe it is an important and excellent contribution. Let's leave v1_path_prefix for the time being and then deprecate it at a later date. The ordering is fine as well (for this formula), so I'd like to go ahead and merge (after your comments about the small changes I mentioned in my review).

@myii myii merged commit ba08792 into saltstack-formulas:master May 26, 2019
@myii
Copy link
Member

myii commented May 26, 2019

@baby-gnu Merged, let's get this important contribution out there. I'll suggest the changes above in a separate PR. Thanks for this!

myii added a commit to myii/systemd-formula that referenced this pull request May 26, 2019
@saltstack-formulas-travis

🎉 This PR is included in version 0.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

aboe76 added a commit that referenced this pull request May 27, 2019
docs(tofs): apply remaining comments from PR #37
saltstack-formulas-travis pushed a commit that referenced this pull request May 27, 2019
## [0.12.1](v0.12.0...v0.12.1) (2019-05-27)

### Documentation

* **tofs:** apply remaining comments from PR [#37](#37) ([d665676](d665676))
@myii
Copy link
Member

myii commented May 28, 2019

@baby-gnu It's a good thing we didn't remove v1_path_prefix -- this was needed when we've been looking at using TOFS in ng formulas! @sticky-note is looking at using it in php-formula now.

@baby-gnu baby-gnu deleted the feature/tofs-lookup-files-in-tpldir-hierarchy branch June 13, 2019 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants