Skip to content

feat(tofs): First implementation #238

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

Merged
merged 1 commit into from
Jun 3, 2019
Merged

feat(tofs): First implementation #238

merged 1 commit into from
Jun 3, 2019

Conversation

sticky-note
Copy link
Member

@sticky-note sticky-note commented May 19, 2019

  1. First implementation of TOFS for:
  • nginx_config,
  • passenger_config,
  • servers_config
  • snippets
  1. Introduced tplroot on modified files as well
  2. Fixed GH link of nginx.conf file in docs/TOFS_pattern.rst

Edited

@myii
Copy link
Contributor

myii commented May 19, 2019

@sticky-note Thanks for this PR.

Initial comments, I haven't looked at this in any detail yet:

  1. Please provide the tofs section in pillar.example, customised to show how to use for these states that have been converted.
  2. To pass the commitlint, you'll need:
-feat(tofs): First imp. for servers_config and snippets
+feat(tofs): first imp. for servers_config and snippets

@sticky-note sticky-note changed the title feat(tofs): First imp. for servers_config and snippets feat(tofs): First implementation May 24, 2019
@myii
Copy link
Contributor

myii commented May 26, 2019

Thanks for this @sticky-note, it's definitely taking shape. I've worked through from each of the entry points, comparing before and after. I've used pillar.example with a couple of minor changes:

  1. Disabled nginx:server:config:source_path.
  2. Set nginx:install_from_source when it was needed.

In a few comments below, I've recommended reducing the number of template file names. Ultimately, the user is able to customise these using the nginx:tofs:source_files:... lookup values set in the pillar/config. Perhaps it's best to actually stick to only one offered template (i.e. the existing one) and leave the rest for users to select.

There's obviously some duplicates below, due to formula execution and loops that are used. These will only require fixing in one place.


nginx.config

     - name: /etc/nginx/nginx.conf
-    - source: salt://nginx/files/nginx.conf
+    - source:
+      - salt://nginx/files/ABC/nginx.conf
+      - salt://nginx/files/ABC/nginx.conf.jinja
+      - salt://nginx/files/Debian/nginx.conf
+      - salt://nginx/files/Debian/nginx.conf.jinja
+      - salt://nginx/files/default/nginx.conf
+      - salt://nginx/files/default/nginx.conf.jinja
  • Fine, may want to consider removing nginx.conf.jinja.

nginx.passenger

     - name: /etc/nginx/conf.d/mod-http-passenger.conf
-    - source: salt://nginx/files/nginx.conf
+    - source:
+      - salt://nginx/files/ABC/nginx.conf
+      - salt://nginx/files/ABC/nginx.conf.jinja
+      - salt://nginx/files/Debian/nginx.conf
+      - salt://nginx/files/Debian/nginx.conf.jinja
+      - salt://nginx/files/default/nginx.conf
+      - salt://nginx/files/default/nginx.conf.jinja
  • Fine, may want to consider removing nginx.conf.jinja.

nginx.servers

     - name: /etc/nginx/sites-available/mysite
-    - source: salt://nginx/files/server.conf
+    - source:
+      - salt://nginx/files/ABC/mysite
+      - salt://nginx/files/ABC/mysite.conf
+      - salt://nginx/files/ABC/server.conf
+      - salt://nginx/files/ABC/server.conf.jinja
+      - salt://nginx/files/Debian/mysite
+      - salt://nginx/files/Debian/mysite.conf
+      - salt://nginx/files/Debian/server.conf
+      - salt://nginx/files/Debian/server.conf.jinja
+      - salt://nginx/files/default/mysite
+      - salt://nginx/files/default/mysite.conf
+      - salt://nginx/files/default/server.conf
+      - salt://nginx/files/default/server.conf.jinja
  • I think four template name options are excessive here, leading to unnecessary I/O lookups -- reducing to two should be sufficient.

nginx.servers_config

     - name: /etc/nginx/sites-available/mysite
-    - source: salt://nginx/files/server.conf
+    - source:
+      - salt://nginx/files/ABC/mysite
+      - salt://nginx/files/ABC/mysite.conf
+      - salt://nginx/files/ABC/server.conf
+      - salt://nginx/files/ABC/server.conf.jinja
+      - salt://nginx/files/Debian/mysite
+      - salt://nginx/files/Debian/mysite.conf
+      - salt://nginx/files/Debian/server.conf
+      - salt://nginx/files/Debian/server.conf.jinja
+      - salt://nginx/files/default/mysite
+      - salt://nginx/files/default/mysite.conf
+      - salt://nginx/files/default/server.conf
+      - salt://nginx/files/default/server.conf.jinja
  • Same as above.
  • TODO (Fix nginx.servers_config #239): Note, there's a bug here that needs to be reported or fixed in a separate PR; when attempting to call nginx.servers_config directly (as is available from the README):
    • Error: Cannot extend ID 'nginx_service' in 'base:nginx.servers_config'. It is not part of the high state.
    • Workaround: Comment out these two lines.

nginx.service

     - name: /lib/systemd/system/nginx.service
-    - source: salt://nginx/files/nginx.service
+    - source:
+      - salt://nginx/files/ABC/nginx.service
+      - salt://nginx/files/ABC/nginx.service.jinja
+      - salt://nginx/files/Debian/nginx.service
+      - salt://nginx/files/Debian/nginx.service.jinja
+      - salt://nginx/files/default/nginx.service
+      - salt://nginx/files/default/nginx.service.jinja
  • Fine, may want to consider removing nginx.service.jinja.

nginx.snippets -- blacklist

-    - name: /etc/nginx/snippets/blacklist.conf
-    - source: salt://nginx/files/server.conf
+    - name: /etc/nginx/snippets/blacklist
+    - source:
+      - salt://nginx/files/ABC/blacklist
+      - salt://nginx/files/ABC/blacklist.jinja
+      - salt://nginx/files/ABC/server.conf
+      - salt://nginx/files/ABC/server.conf.jinja
+      - salt://nginx/files/Debian/blacklist
+      - salt://nginx/files/Debian/blacklist.jinja
+      - salt://nginx/files/Debian/server.conf
+      - salt://nginx/files/Debian/server.conf.jinja
+      - salt://nginx/files/default/blacklist
+      - salt://nginx/files/default/blacklist.jinja
+      - salt://nginx/files/default/server.conf
+      - salt://nginx/files/default/server.conf.jinja
  • Keep the name the same as before, i.e. /etc/nginx/snippets/blacklist.conf.
  • Same as above in respect to reducing to two template names at most.

nginx.snippets -- letsencrypt

-    - name: /etc/nginx/snippets/letsencrypt.conf
-    - source: salt://nginx/files/server.conf
+    - name: /etc/nginx/snippets/letsencrypt
+    - source:
+      - salt://nginx/files/ABC/letsencrypt
+      - salt://nginx/files/ABC/letsencrypt.jinja
+      - salt://nginx/files/ABC/server.conf
+      - salt://nginx/files/ABC/server.conf.jinja
+      - salt://nginx/files/Debian/letsencrypt
+      - salt://nginx/files/Debian/letsencrypt.jinja
+      - salt://nginx/files/Debian/server.conf
+      - salt://nginx/files/Debian/server.conf.jinja
+      - salt://nginx/files/default/letsencrypt
+      - salt://nginx/files/default/letsencrypt.jinja
+      - salt://nginx/files/default/server.conf
+      - salt://nginx/files/default/server.conf.jinja
  • Same as above.

nginx.snippets -- cloudflare_proxy

-    - name: /etc/nginx/snippets/cloudflare_proxy.conf
-    - source: salt://nginx/files/server.conf
+    - name: /etc/nginx/snippets/cloudflare_proxy
+    - source:
+      - salt://nginx/files/ABC/cloudflare_proxy
+      - salt://nginx/files/ABC/cloudflare_proxy.jinja
+      - salt://nginx/files/ABC/server.conf
+      - salt://nginx/files/ABC/server.conf.jinja
+      - salt://nginx/files/Debian/cloudflare_proxy
+      - salt://nginx/files/Debian/cloudflare_proxy.jinja
+      - salt://nginx/files/Debian/server.conf
+      - salt://nginx/files/Debian/server.conf.jinja
+      - salt://nginx/files/default/cloudflare_proxy
+      - salt://nginx/files/default/cloudflare_proxy.jinja
+      - salt://nginx/files/default/server.conf
+      - salt://nginx/files/default/server.conf.jinja
  • Same as above.

nginx.snippets -- upstream_netdata_tcp

-    - name: /etc/nginx/snippets/upstream_netdata_tcp.conf
-    - source: salt://nginx/files/server.conf
+    - name: /etc/nginx/snippets/upstream_netdata_tcp
+    - source:
+      - salt://nginx/files/ABC/upstream_netdata_tcp
+      - salt://nginx/files/ABC/upstream_netdata_tcp.jinja
+      - salt://nginx/files/ABC/server.conf
+      - salt://nginx/files/ABC/server.conf.jinja
+      - salt://nginx/files/Debian/upstream_netdata_tcp
+      - salt://nginx/files/Debian/upstream_netdata_tcp.jinja
+      - salt://nginx/files/Debian/server.conf
+      - salt://nginx/files/Debian/server.conf.jinja
+      - salt://nginx/files/default/upstream_netdata_tcp
+      - salt://nginx/files/default/upstream_netdata_tcp.jinja
+      - salt://nginx/files/default/server.conf
+      - salt://nginx/files/default/server.conf.jinja
  • Same as above.

Copy link
Contributor

@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.

As outlined in #238 (comment).

@myii
Copy link
Contributor

myii commented May 26, 2019

CC: @aboe76 @noelmcloughlin @daks.

Since this is a fairly significant PR, I would appreciate it if any of you could take a look.

@myii
Copy link
Contributor

myii commented May 26, 2019

@sticky-note Please include this fix as well: saltstack-formulas/template-formula#124.

@myii
Copy link
Contributor

myii commented May 26, 2019

! Forumla don't append '.conf' on snippets files any more in order to have the same behavior of nginx:servers:managed. !

My suggestion is to keep this PR as a pure refactor and then apply this in a later PR.

@sticky-note
Copy link
Member Author

sticky-note commented May 27, 2019

Thanks @myii for this review, I updated PR according to your suggestions .
A question remain pending : Is this a good idea to make lookup depending on server name on the the two reviews below ?

@myii myii mentioned this pull request May 27, 2019
Copy link
Contributor

@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.

This is definitely taking shape now and just a few changes from my side -- great work.

{% else %}
{% set source_path = 'salt://nginx/files/server.conf' %}
{% endif %}
{% if settings.enabled == True %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't looked into this but is there a reason you removed the settings.config != None?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this to be able to not specify a config object so that flat files can be retrieved by TOFS without this param set empty

@@ -138,7 +144,7 @@ nginx_server_available_dir:
{% else %}
{{ manage_status(server, settings.enabled, False) }}
{% endif %}
{% if settings.config != None and settings.enabled == True %}
{% if settings.enabled == True %}
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't looked into this but is there a reason you removed the settings.config != None?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this to be able to not specify a config object so that flat files can be retrieved by TOFS without this param set empty

pillar.example Outdated
@@ -84,6 +85,8 @@ nginx:
- upstream netdata:
- server: 127.0.0.1:19999
- keepalive: 64
file_retrieved_by_tofs: {} # File retrieved by TOFS,
Copy link
Contributor

Choose a reason for hiding this comment

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

How would this be used exactly?

Copy link
Member Author

@sticky-note sticky-note Jun 2, 2019

Choose a reason for hiding this comment

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

Don't know how to explain that, it will search files :

nginx/files/ABC/file_retrieved_by_tofs
nginx/files/ABC/server.conf
nginx/files/default/file_retrieved_by_tofs
nginx/files/default/server.conf

without modifying TOFS parameters

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this already provided by the tofs section of the pillar? I.e.:

  tofs:
    ...
    source_files:
      ...
      nginx_snippet_file_managed:
        - file_retrieved_by_tofs
        - server.conf

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the default behavior without specifying anything in pillar

Copy link
Contributor

@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.

Still a few more issues! Don't worry, this happens with large, important PRs.

pillar.example Outdated
# source_files:
# template-config-file-file-managed:
# - 'example_alt.tmpl'
# - 'example_alt.tmpl.jinja'
Copy link
Contributor

Choose a reason for hiding this comment

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

These four lines should be removed since the section is shown below.

pillar.example Outdated
- role
- osfinger
- os
- os_family
Copy link
Contributor

Choose a reason for hiding this comment

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

This files_switch section is better commented out since we don't really want the extra I/O unless necessary.

pillar.example Outdated
@@ -84,6 +85,8 @@ nginx:
- upstream netdata:
- server: 127.0.0.1:19999
- keepalive: 64
file_retrieved_by_tofs: {} # File retrieved by TOFS,
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this already provided by the tofs section of the pillar? I.e.:

  tofs:
    ...
    source_files:
      ...
      nginx_snippet_file_managed:
        - file_retrieved_by_tofs
        - server.conf

@myii
Copy link
Contributor

myii commented Jun 3, 2019

@aboe76 @noelmcloughlin @daks I'd really appreciate a second review on this PR. It's pretty much complete now so can be tested to ensure it is satisfactory.

@daks
Copy link
Member

daks commented Jun 3, 2019

@myii I'll try to find some time to review this PR, but I've no real knowledge of TOFS :-/

First implementation of TOFS for:
nginx_config, passenger_config, servers_config and snippets
Introduced tplroot on modified files as well
Fixed GH link of nginx.conf file in docs/TOFS_pattern.rst
Fixed test for snippets name pillar
@myii myii merged commit f036e31 into saltstack-formulas:master Jun 3, 2019
@myii
Copy link
Contributor

myii commented Jun 3, 2019

Brilliant work @sticky-note -- this has been merged.
No problem @daks, I've already done a number of test runs, thanks for the offer.

@saltstack-formulas-travis

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

myii added a commit to saltstack-formulas/template-formula that referenced this pull request Jul 25, 2019
saltstack-formulas-travis pushed a commit to saltstack-formulas/template-formula that referenced this pull request Jul 25, 2019
## [3.1.1](v3.1.0...v3.1.1) (2019-07-25)

### Bug Fixes

* **tofs:** prepend the config-based `source_files` to the default ([3483e76](3483e76)), closes [/github.com/saltstack-formulas/nginx-formula/pull/247#issuecomment-514262549](https://github.com//github.com/saltstack-formulas/nginx-formula/pull/247/issues/issuecomment-514262549) [#151](#151)

### Documentation

* **tofs:** ensure merged will all recent changes ([6a614d9](6a614d9))
* **tofs:** update from `nginx-formula` ([23a221e](23a221e)), closes [/github.com/saltstack-formulas/nginx-formula/pull/238#discussion_r289124365](https://github.com//github.com/saltstack-formulas/nginx-formula/pull/238/issues/discussion_r289124365)
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