Skip to content

Set force_mod_watch in docker_container.running for lightweight changes - #17

Open
mitar wants to merge 5 commits into
salt-extensions:mainfrom
mitar:docker-container-force-mod-watch
Open

mitar wants to merge 5 commits into
salt-extensions:mainfrom
mitar:docker-container-force-mod-watch

Conversation

@mitar

@mitar mitar commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

When the normal run produces only lightweight changes (such as a network reconnect) and does not recreate or restart the container, return force_mod_watch: True so the state system still invokes mod_watch for a watched trigger. Previously the watched-state trigger was silently dropped in this case - for example, a watched config-file change would not force-replace the container if docker_container.running happened to also reconnect a network during the same run.

Heavy-change keys (container_id, state, image, forced_update) already indicate the container was recreated or restarted, so mod_watch is not needed in those cases.

The force_mod_watch return key is handled by the state system since saltstack/salt#68960 (currently on Salt's master branch). Older Salt versions do not act on it.

See: saltstack/salt#68958

Merge requirements satisfied?

[NOTICE] Bug fixes or new features require tests.

Commits signed with GPG?

No

@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.03896% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.09%. Comparing base (3bc2a01) to head (b7b539c).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
tests/unit/states/test_docker_container.py 49.15% 30 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
+ Coverage   42.88%   43.09%   +0.21%     
==========================================
  Files          26       27       +1     
  Lines        6564     6641      +77     
  Branches     1122     1123       +1     
==========================================
+ Hits         2815     2862      +47     
- Misses       3494     3524      +30     
  Partials      255      255              
Flag Coverage Δ
Linux 43.08% <61.03%> (+0.21%) ⬆️
project 38.45% <100.00%> (+0.02%) ⬆️
py310 43.03% <61.03%> (+0.21%) ⬆️
py311 43.03% <61.03%> (+0.21%) ⬆️
py314 43.03% <61.03%> (+0.21%) ⬆️
salt_3006_27 43.03% <61.03%> (+0.21%) ⬆️
salt_3008_2 43.03% <61.03%> (+0.21%) ⬆️
tests 51.63% <60.00%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mitar
mitar force-pushed the docker-container-force-mod-watch branch from a17b27c to b7b539c Compare October 20, 2026 17:06

@m-czernek m-czernek left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall the change looks ok to me, though saltstack/salt#68960 was merged only in master, which means it'll be available in 3009.

In that case I'd prefer to wait for 3009 release with this PR (it has no effect otherwise). If you backport it to 3008, then I've left two minor comments, after which we can merge this.

When the normal run produces only lightweight changes (such as a network
reconnect) and does not recreate or restart the container, return
`force_mod_watch: True` so the state system still invokes `mod_watch`
for a watched trigger. Previously the watched-state trigger was silently
dropped in this case - for example, a watched config-file change would
not force-replace the container if `docker_container.running` happened
to also reconnect a network during the same run.

Heavy-change keys (`container_id`, `state`, `image`,
`forced_update`) already indicate the container was recreated or
restarted, so `mod_watch` is not needed in those cases.

The `force_mod_watch` return key is handled by the state system since
saltstack/salt#68960 (currently on Salt's master branch). Older Salt
versions do not act on it.

See: saltstack/salt#68958
Use an allow list instead of a block list: docker_container.running now
returns force_mod_watch only when its only change was reconnecting
networks, and never in test mode. This also stops a mod_watch run which
sends a signal from returning the flag.

The comment and the changelog now say that the flag has an effect only
with Salt versions which include saltstack/salt#68960.
@mitar
mitar force-pushed the docker-container-force-mod-watch branch from b7b539c to 19e1718 Compare November 27, 2026 12:03
@mitar

mitar commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I applied both suggestions.

About waiting for 3009: since the Docker code now lives in this extension, which is released independently of Salt and supports salt>=3006, I think it would be useful to merge this already:

The noxfile already supports SALT_REQUIREMENT=salt==master for running the tests against Salt master.

I also rebased the branch onto current main, and the commits are now signed.

The functional test read force_mod_watch from the state's result, which
works only while Salt leaves the key in results. saltstack/salt#70972
removes it from every result, so the test now checks the change which
the flag depends on: connecting a network reports only network changes,
and the container keeps its Id and its start time. The unit tests check
the flag itself.
@mitar

mitar commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

I pushed one more commit: the functional test no longer reads force_mod_watch from the state's result. It now checks that connecting a network reports only container.Networks changes and keeps the container's Id and start time, which is the case the flag is set for. The flag itself is covered by the unit tests.

The reason is saltstack/salt#70972, which I opened while testing this PR against Salt master: it removes force_mod_watch from state results, so a test reading it from there would break once it is merged. It also fixes test=True runs of watching states which set the flag being reported as failed; this PR does not set the flag in test mode, so it is not affected. I ran the rewritten test under Salt 3008.5, Salt master, and Salt master with saltstack/salt#70972.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants