Add filewatcher capabilities to kanto-auto-deployer #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We want kanto-auto-deployer to be able to run in two modes:
Other issues:
Solution
A new cli flag
--daemon/-d
was added that sets the operation mode of KAD.If the flag is not passed, KAD works in "one-shot" mode (minimal changes here)
If the flag is passed:
The one-shot directory deployment is ran and then an async_watcher is set-up through the new module fs_watch. This module polls the directory every 10 seconds (
const POLL_SECONDS: f64 = 10.0;
) and if FS events have occurred during that interval it de-bounces them (multiple modifications -> single trigger at the end) it triggers a callback function.That callback
redeploy_on_change
goes through all newly added json files/modified existing ones and deploys the containers specified in those manifests. If the container already exists (e.g. it's already deployed) it is first stopped, then removed and created again. This ensures that the latest state described in the manifest will be used when running as a daemon.The "filewatcher" feature flag
To reduce binary bloat, all filewatcher/deamon functionality has been "namespaced" under the "filewatcher" compilation flag. This is a default feature, so running
cargo build --release
will yield a version of KAD that has this mode available for use.To compile without daemon mode run
cargo build --release --no-default-features
. This will yield a binary that only has the "one-shot" mode.Screenshots:
![image](https://user-images.githubusercontent.com/59696861/228213494-396ac08a-5c13-4d5e-9363-2ca1e49685e9.png)
Help:
One-shot mode:
![image](https://user-images.githubusercontent.com/59696861/228214566-6d421424-9f55-4c5a-b79d-adba3e5f075a.png)
Daemon mode:
As it can be seen on the screenshots only the created/modified files are taken into account. If the manifest is correct (e.g.
vum.json
) it will be redeployed. If not (e.g.wrong.json
) it would log an error and continue with the monitoring.Compiled with --no-default-features:
![image](https://user-images.githubusercontent.com/59696861/228568216-7316cb01-6b5b-4519-b081-a17f357cc3d6.png)
Footprint (on QEMUx86 + kvm) in daemon mode (service):
Size with filewatcher: 4.2 M (most of the increase is due to the clap CLI parser)
RAM usage: 1.4 M
CPU: 0.0 all cores (from htop)