Ignore synced config zones where no config item exists #7120
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.
Story
User renames/deletes zone configuration in zones.conf on the client
This isn't related to the config sync per se, and requires configuration changes followed by reloads on the client itself (admin action).
Currently, the entire configuration in
/var/lib/icinga2/api/zones
is included during config compilation.At this stage in the config compiler, we don't have any objects activated yet, so we cannot check against non-configured zone objects unfortunately.
This leads into this perpetum mobile situation:
The configuration is loaded and compiled ...
... but the config validation fails since the Zone object 'global-templates' does not exist.
Solution
Really a problem, since we can only guess which zones may survive the config compiler. Since we would end in a broken configuration validation later on if zones contain errors, we can use this advantage to enforce a guess.
How?
By making the bold statement that you cannot sync zones via cluster zone sync for this specific instance.
This way, we can fairly assume that the configuration for zones was done statically/via API package.
The solution is to check whether a configitem of the type "Zone" and the directory name already exists.
This solves #3323
Upon next config sync, the directories are automatically purged then (requires the solution with staged syncs).
Technical Details
The culprit is that we're in compiling configuration stage here,
we don't have access to
Zone::GetByName()
as objects have notbeen activated yet.
Our best guess is from a config item loaded before (e.g. from zones.conf)
since no-one can sync zones via cluster config sync either.
It may not be 100% correct since the zone object itself may be invalid.
Still, if the zone object validator fails later, the config breaks either way.
The problem with removal of these directories is dealt by the cluster
config sync with stages.
refs #6727
refs #6716
fixes #3323