Feature request: cleanup old mine data on master
Whenever I remove a node, master still keeps it's mine information cached and sends it to all minions. Calling salt '*' mine.flush doesn't help, as master still has old mine data from not existing nodes. Calling salt-run cache.clear_mine on master also leaves all the cached data on master unchanged.
As a manual fix, I had to go to /var/cache/salt/master/minons and manually remove directories for minions, which don't exist anymore.
Are you using salt-cloud to build and destroy servers?
https://github.com/saltstack/salt/blob/develop/salt/cloud/libcloudfuncs.py#L360
This is what I use (still needs to be fully documented) but if you have flush_mine_on_destroy: True in the cloud profile. Other than that, I would like to have something to just remove old mines as well.
flush_mine_on_destroy: True works fine, thanks for the tip, didn't find it in the docs. I'm leaving issue open, as removing old mine data still seems helpful.
This would be very useful, thanks!
Ran into this and I thought it was strange that the master wouldn't expire mine data from non-existent minions. It was rather puzzling until I found this and saw that others encountered the same thing.
Workaround that I use from within a state that sets up my salt-masters:
remove_stale_mine_data:
cmd.run:
- name: >
find /var/cache/salt/master/minions/ -type f -name mine.p
! -newermt '-90 min' -exec bash '-c' 'rm -rf "$(dirname "{}")"' ';'
Nice, thanks for the workaround!
FWIW, I set my mine_interval at 60. So this means that files are only purged after 1.5x the interval. Salt should probably have similar logic in the master.
Ran into the same issue. I didn't destroy some servers using salt-cloud, so flush_mine_on_destroy didn't work of course.
@marek-obuchowicz: Thanks for the workaround, that did the trick for me...
Is there a reason not to just default that option to True? Seems like it'd be an strange default to keep the mine data.
@wt You mean flush_mine_on_destroy? Yes, it does seem like True is a saner default there. I'll have to ask around for potential pitfalls there.
@basepi ack
For what it's worth, mine data being removed when salt-cloud destroyed a minion is what I expected. Ended up at this issue trying to figure out why that wasn't happening.
@wt thanks for your example, I created a runner based on it over at salt-mine-refresh that can be called from events, scheduled, etc
:+1: for this feature, it can cause some weird issues for formulas which relies on this information like HDFS
Yea I can't use salt-cloud to destroy and just assumed when salt-key -d was used it would cleanup mine. Thought it was a bug. Workaround from @wt works for me, but wished it was automatic.
I used salt-cloud to destroy an instance with flush_mine_on_destroy: True in salt 2015.5.3 and the data was left behind.
༼ ༎ຶ ෴ ༎ຶ༽
I'd like to add my vote for this feature. It seems more like a bug fix to me though. I'm not the most advanced user, but I can't think of a scenario where keeping the mine data for deleted nodes by default would be expected behavior.
Can we at least get some doc updates about the current behavior? I'm finding myself having to look at GitHub issues and source code instead of the docs very frequently to get a handle on the actual way that SaltStack functions, which is unfortunate.
I'm going to look into possibly adding this for Boron. No promises, though, I've assigned myself too much work for Boron already. ;)
Thanks @basepi! I ran into this earlier today and while it was diagnosed fairly quickly, it certainly didn't seem like intended/expected functionality. I personally expected a minion's cached data to get deleted once their key is revoked. Even some sort of sync or refresh functionality for the master's cache would work I suppose.
+1 I also thought this would be the default behaviour. Looking forward to get this feature in the next release.