Skip to content

Makes postgres-reload-modules conditional #216

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions postgres/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ postgres:

bake_image: False

manage_force_reload_modules: False

fromrepo: ''

users: {}
Expand Down
2 changes: 1 addition & 1 deletion postgres/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{ state }}-{{ name }}:
{{ state }}.{{ ensure|default('present') }}:
{{- format_kwargs(kwarg) }}
- onchanges:
- watch:
- test: postgres-reload-modules

{%- endmacro %}
Expand Down
8 changes: 7 additions & 1 deletion postgres/manage.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{%- from tpldir + "/map.jinja" import postgres with context -%}
{%- from tpldir + "/macros.jinja" import format_state with context -%}

{%- if salt['postgres.user_create']|default(none) is not callable %}
{%- set needs_client_binaries = salt['postgres.user_create']|default(none) is not callable -%}

{%- if needs_client_binaries %}

# Salt states for managing PostgreSQL is not available,
# need to provision client binaries first
Expand All @@ -18,7 +20,11 @@ include:
# Ensure that Salt is able to use postgres modules

postgres-reload-modules:
{%- if needs_client_binaries or postgres.manage_force_reload_modules %}
test.succeed_with_changes:
{%- else %}
test.succeed_without_changes:
{%- endif %}
Copy link
Contributor

Choose a reason for hiding this comment

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

@RobRuana This seems like an obvious fix, but that wouldn't work.
Each state generated below explicitly subscribed on changes in postgres-reload-modules. So if you later change PG entities in the Pillar, it will not have any effect.
The only way I see to overcome this: you need to put conditional in format_state macro to depend on modules reload only when postgres.manage_force_reload_modules set True.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vutny, yes, you are correct that this breaks any state using the format_state() macro.

At first I couldn't understand why onchanges: postgres-reload-modules was being used instead of require: postgres-reload-modules. But then I realized that many instances of format_state() are already using the require conditional, so there would be conflicting require keys when the state is rendered.

Correct me if I'm wrong, but I believe onchanges is being used to force correct ordering of the states, not because we want every format_state() to run when there are changes in postgres-reload-modules.

If that's correct, then we should be able to achieve the same result by using watch instead of onchanges in format_state(). I've made that change. Please let me know if you think that works.

- reload_modules: True

# User states
Expand Down
16 changes: 9 additions & 7 deletions postgres/server/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ postgresql-conf:

{%- endif %}

# Restart the service where reloading is not sufficient
# Currently when the cluster is created or changes made to `postgresql.conf`
postgresql-service-restart:
module.wait:
- name: service.restart
- m_name: {{ postgres.service }}

{%- set pg_hba_path = salt['file.join'](postgres.conf_dir, 'pg_hba.conf') %}

postgresql-pg_hba:
Expand All @@ -176,6 +169,15 @@ postgresql-pg_hba:
{%- endif %}
- require:
- file: postgresql-config-dir
- watch_in:
- module: postgresql-service-restart
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've found that simply reloading the postgres service is not enough to pick up ACL changes in pg_hba.conf. A full restart is required.

This is on ubuntu 18.04 with postgres 10.


# Restart the service where reloading is not sufficient
# Currently when the cluster is created or changes made to `postgresql.conf`
postgresql-service-restart:
module.wait:
- name: service.restart
- m_name: {{ postgres.service }}

{%- set pg_ident_path = salt['file.join'](postgres.conf_dir, 'pg_ident.conf') %}

Expand Down