[FEATURE REQUEST] State ordering enhancements in failure conditions
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Is your feature request related to a problem? Please describe.
This is more or less a rehash of https://github.com/saltstack/salt/issues/15886 which was closed due to staleness.
Consider the following:
- State ordering is done via requisites rather than
orderin a state tree, as recommended by the docs. For example, the following state IDs should follow this order:foo→bar→baz→quux, and thusbarhas arequireoffoo,bazhas arequireofbar, and so forth.- (With the exception of one or two states which absolutely must be run very last, unquestionably, and thus have
- order: last.)
- (With the exception of one or two states which absolutely must be run very last, unquestionably, and thus have
- A master is configured with
failhard: truewith the intent of selectively settingfailhard: falseon explicit states that MAY fail, but failure state is acceptable. For example,foois prone to failure, but its failure (or partial failure which would squash down to a failure since theresultin ret is a boolean for most (all?) state/execution modules) is acceptable.- Thus in this scenario,
foohas- failhard: False.
- Thus in this scenario,
baris in an included SLS, and MUST ALWAYS proceed afterfooregardless if it has failed or not. It is expected to/never should fail, and thus ITSfailhardis implicitlyTrue(as per the master configuration).- HOWEVER, because the only available ordering requisite appropriate for this is
require, iffoofails thenbarwill never run. Even though it's supposed to. This means either its state fails, ending the entire run erroneously, or it necessitates a wholly and completely inappropriate- failhard: Falseas well, because...
- HOWEVER, because the only available ordering requisite appropriate for this is
bazhas arequireforbar. This then means thatbazwill fail ifbarfails, ifbarstill has the implicitfailhard: Trueset, and will STILL never run (even though it should) IFfooFAILS, as thus its failure has now cascaded intobazand, as a result,bazfaces the exact same conundrum re:failhardasbarabove.- This now leads to effectively setting
failhardto False for the entire chain atbaronwards JUST to getquuxto always run, which is incorrect for the expectations ofbar,baz, andquux.
And so on, and so on. Leading to a cascading mess.
Describe the solution you'd like
Two new global requisites should be added:
after(or reasonable analogue), a "softer"requirethat is strictly used for ordering dependency and not state dependencybefore(or reasonable analogue), a "softer"require_in(again tied strictly to ordering rather than state dependency)
with the intent that only after OR require in a given state for a given preceding state ID is given (and likewise for before/require_in).
Describe alternatives you've considered
The only possible alternative is duplicating every single state in the chain after the first "soft-fail" state, one with require and failhard: False and another with onfail and the implicit failhard: True. onfail does not execute if its preceding dependency SUCCEEDS, so it cannot be used alone without a paired require state. Using both require and onfail in the same state declaration for the same preceding state ID leads to a logic condition in which the state will never ever be run (they are AND'd instead of OR'd), but even if they were OR'd the state would STILL need the inappropriate - failhard: False.
This, as you can imagine, is tedious in larger state trees that may include conditional states:
$ find ./ -type f -name '*.sls' | wc -l
307
$ find ./ -type f -name '*.sls' -exec grep -Ec '^[A-Za-z0-9]+.*:\s*' '{}' \; | awk '{s+=$1} END {print s}'
1420
Additional context
N/A.
Please Note
If this feature request would be considered a substantial change or addition, this should go through a SEP process here https://github.com/saltstack/salt-enhancement-proposals, instead of a feature request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files or tests; begin by locating Salt's existing require and require_in requisite handling and its failhard evaluation. Compare the proposed after and before semantics with current ordering and failure propagation. Done would require an agreed design, likely through the Salt Enhancement Proposal process, plus tests covering failed and successful prerequisite states.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100