Skip to content

Commit feea4f1

Browse files
committed
fix(postgres.manage): only reload modules if needed; fixes saltstack-formulas#214
Based on the great work of @RobRuana in saltstack-formulas#216.
1 parent e9068bf commit feea4f1

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

postgres/defaults.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ postgres:
7373

7474
bake_image: False
7575

76+
manage_force_reload_modules: False
77+
7678
fromrepo: ''
7779

7880
users: {}

postgres/macros.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{{ state }}-{{ name }}:
2626
{{ state }}.{{ ensure|default('present') }}:
2727
{{- format_kwargs(kwarg) }}
28-
- onchanges:
28+
- require:
2929
- test: postgres-reload-modules
3030

3131
{%- endmacro %}

postgres/manage.sls

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{%- from tpldir + "/map.jinja" import postgres with context -%}
22
{%- from tpldir + "/macros.jinja" import format_state with context -%}
33
4-
{%- if salt['postgres.user_create']|default(none) is not callable %}
4+
{%- set needs_client_binaries = salt['postgres.user_create']|default(none) is not callable -%}
5+
6+
{%- if needs_client_binaries %}
57
68
# Salt states for managing PostgreSQL is not available,
79
# need to provision client binaries first
@@ -18,7 +20,12 @@ include:
1820
# Ensure that Salt is able to use postgres modules
1921
2022
postgres-reload-modules:
21-
test.succeed_with_changes:
23+
test.configurable_test_state:
24+
- changes:
25+
{%- if needs_client_binaries or postgres.manage_force_reload_modules %} True
26+
{%- else %} False
27+
{%- endif %}
28+
- result: True
2229
- reload_modules: True
2330
2431
# User states
@@ -35,7 +42,7 @@ postgres-reload-modules:
3542
3643
{{ format_state(name, 'postgres_tablespace', tblspace) }}
3744
{%- if 'owner' in tblspace %}
38-
- require:
45+
{#- - require: #}
3946
- postgres_user: postgres_user-{{ tblspace.owner }}
4047
{%- endif %}
4148
@@ -49,7 +56,7 @@ postgres-reload-modules:
4956
{%- do extension.update({'name': ext_name, 'maintenance_db': name}) %}
5057
5158
{{ format_state( name + '-' + ext_name, 'postgres_extension', extension) }}
52-
- require:
59+
{#- - require: #}
5360
- postgres_database: postgres_database-{{ name }}
5461
{%- if 'schema' in extension and 'schemas' in postgres %}
5562
- postgres_schema: postgres_schema-{{ name }}-{{ extension.schema }}
@@ -62,15 +69,15 @@ postgres-reload-modules:
6269
{%- do schema.update({'name': schema_name, 'dbname': name }) %}
6370
6471
{{ format_state( name + '-' + schema_name, 'postgres_schema', schema) }}
65-
- require:
72+
{#- - require: #}
6673
- postgres_database: postgres_database-{{ name }}
6774
6875
{%- endfor %}
6976
{%- endif %}
7077
7178
{{ format_state(name, 'postgres_database', db) }}
7279
{%- if 'owner' in db or 'tablespace' in db %}
73-
- require:
80+
{#- - require: #}
7481
{%- endif %}
7582
{%- if 'owner' in db %}
7683
- postgres_user: postgres_user-{{ db.owner }}
@@ -86,7 +93,7 @@ postgres-reload-modules:
8693
{%- for name, schema in postgres.schemas|dictsort() %}
8794
8895
{{ format_state(name, 'postgres_schema', schema) }}
89-
- require:
96+
{#- - require: #}
9097
- postgres_database-{{ schema.dbname }}
9198
{%- if 'owner' in schema %}
9299
- postgres_user: postgres_user-{{ schema.owner }}
@@ -99,9 +106,7 @@ postgres-reload-modules:
99106
{%- for name, extension in postgres.extensions|dictsort() %}
100107
101108
{{ format_state(name, 'postgres_extension', extension) }}
102-
{%- if 'maintenance_db' in extension or 'schema' in extension %}
103-
- require:
104-
{%- endif %}
109+
{#- - require: #}
105110
{%- if 'maintenance_db' in extension %}
106111
- postgres_database: postgres_database-{{ extension.maintenance_db }}
107112
{%- endif %}

0 commit comments

Comments
 (0)