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

Minion has the option to skip pillars #67216

Draft
wants to merge 1 commit 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
6 changes: 6 additions & 0 deletions conf/minion
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@
# protected accordingly.
#minion_pillar_cache: False

# When set to True the minion will not request a pillar from the master upon
# startup. Pillar can still be fetched later via a manual operation like
# `saltutil.refresh_pillar` or similar. Enabling this option might break pillar
# related functionality (e.g. pillar targeter).
#skip_init_pillar: False

# Grains cache expiration, in seconds. If the cache file is older than this
# number of seconds then the grains cache will be dumped and fully re-populated
# with fresh data. Defaults to 5 minutes. Will have no effect if 'grains_cache'
Expand Down
5 changes: 5 additions & 0 deletions salt/cli/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def run(self):
self.config["extension_modules"] = os.path.join(cache_dir, "extmods")
prepend_root_dir(self.config, ["cachedir", "extension_modules"])

if self.config["fun"].split(".")[0] == "pillar":
if self.options.skip_init_pillar:
self.options.skip_init_pillar = False
self.config["skip_init_pillar"] = False

caller = salt.cli.caller.Caller.factory(self.config)

if self.options.doc:
Expand Down
6 changes: 6 additions & 0 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ def _gather_buffer_space():
"pillar_cache_ttl": int,
# Pillar cache backend. Defaults to `disk` which stores caches in the master cache
"pillar_cache_backend": str,
# When set to True the minion will not request a pillar from the master upon startup.
# Pillar can still be fetched later via a manual operation like `saltutil.refresh_pillar` or
# similar. Enabling this option might break pillar related functionality (e.g. pillar
# targeter).
"skip_init_pillar": bool,
# Cache the GPG data to avoid having to pass through the gpg renderer
"gpg_cache": bool,
# GPG data cache TTL, in seconds. Has no effect unless `gpg_cache` is True
Expand Down Expand Up @@ -1077,6 +1082,7 @@ def _gather_buffer_space():
"pillar_cache_backend": "disk",
"request_channel_timeout": 60,
"request_channel_tries": 3,
"skip_init_pillar": False,
"gpg_cache": False,
"gpg_cache_ttl": 86400,
"gpg_cache_backend": "disk",
Expand Down
40 changes: 23 additions & 17 deletions salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,16 @@ def gen_modules(self, initial_load=False, context=None):
if context is None:
context = {}
if initial_load:
self.opts["pillar"] = salt.pillar.get_pillar(
self.opts,
self.opts["grains"],
self.opts["id"],
self.opts["saltenv"],
pillarenv=self.opts.get("pillarenv"),
).compile_pillar()
if self.opts.get("skip_init_pillar", False):
self.opts["pillar"] = {}
else:
self.opts["pillar"] = salt.pillar.get_pillar(
self.opts,
self.opts["grains"],
self.opts["id"],
self.opts["saltenv"],
pillarenv=self.opts.get("pillarenv"),
).compile_pillar()

self.utils = salt.loader.utils(self.opts, context=context)
self.functions = salt.loader.minion_mods(
Expand Down Expand Up @@ -1427,16 +1430,19 @@ def _post_master_init(self, master):
if self.connected:
self.opts["master"] = master

# Initialize pillar before loader to make pillar accessible in modules
async_pillar = salt.pillar.get_async_pillar(
self.opts,
self.opts["grains"],
self.opts["id"],
self.opts["saltenv"],
pillarenv=self.opts.get("pillarenv"),
)
self.opts["pillar"] = yield async_pillar.compile_pillar()
async_pillar.destroy()
if self.opts.get("skip_init_pillar", False):
self.opts["pillar"] = {}
else:
# Initialize pillar before loader to make pillar accessible in modules
async_pillar = salt.pillar.get_async_pillar(
self.opts,
self.opts["grains"],
self.opts["id"],
self.opts["saltenv"],
pillarenv=self.opts.get("pillarenv"),
)
self.opts["pillar"] = yield async_pillar.compile_pillar()
async_pillar.destroy()

if not self.ready:
self._setup_core()
Expand Down
15 changes: 15 additions & 0 deletions salt/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,21 @@ def _mixin_setup(self):
action="store_true",
help="Do not load grains.",
)
self.add_option(
"--no-skip-init-pillar",
default=True,
action="store_false",
dest="skip_init_pillar",
help=(
"Explicitly load pillar on minion startup (overrides any skip_init_pillar in /etc/salt/minion)"
),
)
self.add_option(
"--skip-pillars",
default=False,
action="store_true",
help=("Do not load pillars."),
)
self.add_option(
"--refresh-grains-cache",
default=False,
Expand Down
Loading