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

refactor(sls): make states more readable by spliting into sub-components #529

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
89 changes: 0 additions & 89 deletions salt/master.sls

This file was deleted.

60 changes: 60 additions & 0 deletions salt/master/config/files.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split("/")[0] %}
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
{%- set sls_package_install = tplroot ~ ".master.package.install" %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

include:
- {{ sls_windows_excluded }}
- {{ sls_package_install }}

{%- if salt_settings.master_config_use_TOFS %}
{%- set source = files_switch(["master.d"],
lookup="salt-master"
) %}
{%- set template = "" %}
{%- else %}
{%- set source = "salt://" ~ tplroot ~ "/files/master.d" %}
{%- set template = "jinja" %}
{%- endif %}

salt-master-config-files-file.recurse:
file.recurse:
- name: {{ salt_settings.config_path }}/master.d
- source: {{ source }}
- template: {{ template }}
- clean: {{ salt_settings.clean_config_d_dir }}
- exclude_pat:
- _*
- raas.conf
- require:
- sls: {{ sls_windows_excluded }}
- sls: {{ sls_package_install }}

{%- if salt_settings.master_remove_config %}
salt-master-config-files-remove-old-master-conf-file.absent:
file.absent:
- name: {{ salt_settings.config_path }}/master
- require:
- sls: {{ sls_windows_excluded }}
- sls: {{ sls_package_install }}
{%- endif %}

# clean up old _defaults.conf file if they have it around
salt-master-config-files-remove-old-default-master-conf-file.absent:
file.absent:
- name: {{ salt_settings.config_path }}/master.d/_defaults.conf

{%- if grains.os == "MacOS" %}
salt-master-config-files-macos-LaunchDaemons-file.managed:
file.managed:
- name: /Library/LaunchDaemons/com.saltstack.salt.master.plist
- source: https://raw.githubusercontent.com/saltstack/salt/master/pkg/osx/scripts/com.saltstack.salt.master.plist
- source_hash: {{ salt_settings.salt_master_macos_plist_hash }}
- retry: {{ salt_settings.retry_options | json }}
- require:
- sls: {{ sls_package_install }}
{%- endif %}
5 changes: 5 additions & 0 deletions salt/master/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .files
54 changes: 54 additions & 0 deletions salt/master/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

include:
- .package
- .config
- .service

{#- Be backward compatible #}
{%- if grains.kernel != 'Windows' %}
{%- if grains.os == "MacOS" %}
salt-master-macos:
test.show_notification:
- name: salt-master-macos
- text: Backward compatible state for {{
"'sls:" ~ tplroot ~ ".master.config.files => "
~ "salt-master-config-files-macos-LaunchDaemons-file.managed'"
}}
{%- endif %}

{%- set old_states_names = [
"'sls:" ~ tplroot ~ ".master.package.install => "
~ "salt-master-package-install-pkg.installed'",
"'sls:" ~ tplroot ~ ".master.config.files => "
~ "salt-master-config-files-file.recurse'",
"'sls:" ~ tplroot ~ ".master.service",
] %}
salt-master:
test.show_notification:
- name: salt-master
- text: Backward compatible state for {{ old_states_names | join(", ") }}

{%- if salt_settings.master_remove_config %}
remove-default-master-conf-file:
test.show_notification:
- name: remove-default-master-conf-file
- text: Backward compatible state for {{
"'sls:" ~ tplroot ~ ".master.config.files => "
~ "salt-master-config-files-remove-old-master-conf-file.absent'"
}}
{%- endif %}

remove-old-master-conf-file:
test.show_notification:
- name: remove-old-master-conf-file
- text: Backward compatible state for {{
"'sls:" ~ tplroot ~ ".master.config.files => "
~ "salt-master-config-files-remove-old-default-master-conf-file.absent'"
}}
{%- endif %}
5 changes: 5 additions & 0 deletions salt/master/package/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
26 changes: 26 additions & 0 deletions salt/master/package/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_windows_excluded = tplroot ~ '.windows-excluded' %}
{%- set sls_pin_version = tplroot ~ '.pin' %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

{#- `salt-master` cannot be installed on Windows machines #}
{%- set sls_dependencies = [sls_windows_excluded] %}

{%- if salt_settings.pin_version and salt_settings.version and grains.os_family|lower == 'debian' %}
{%- do sls_dependencies.append(sls_pin_version) %}
{%- endif %}

include: {{ sls_dependencies }}

{%- if salt_settings.install_packages %}
salt-master-package-install-pkg.installed:
pkg.installed:
- name: {{ salt_settings.salt_master }}
- version: {{ salt_settings.version | default('~') }}
- require:
- sls: {{ sls_windows_excluded }}
{%- endif %}
28 changes: 28 additions & 0 deletions salt/master/service/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_windows_excluded = tplroot ~ ".windows-excluded" %}
{%- set sls_config_files = tplroot ~ '.master.config.files' %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}

{%- if salt_settings.master_service_details.state != 'ignore' %}
include:
- {{ sls_windows_excluded }}
- {{ sls_config_files }}

{%- set wanted_state = salt_settings.master_service_details.state %}
{%- set retry = {
'darwin': salt_settings.retry_options | json,
}.get(grains.kernel|lower, '')
%}

salt-master-service-{{ wanted_state }}:
service.{{ wanted_state }}:
- enable: {{ salt_settings.master_service_details.enabled }}
- name: {{ salt_settings.master_service }}
- retry: {{ retry }}
- watch:
- sls: {{ sls_config_files }}
{%- endif %}
15 changes: 15 additions & 0 deletions salt/windows-excluded.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- if grains.kernel == 'Windows' %}
salt-windows-excluded-test.fail_without_changes:
test.fail_without_changes:
- name: Verify that current platform is not Windows
- comment: Platform Windows is not supported
{%- else %}
{#- Workaround https://github.com/saltstack/salt/issues/10852 #}
salt-windows-excluded-test.succeed_without_changes:
test.succeed_without_changes:
- name: Verify that current platform is not Windows
- comment: Platform {{ grains.kernel }} is supported
{%- endif %}