ROX-15904: migrate caching node scanner #1130
Merged
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.
This PR updates the Node Scanner that was introduced in #1116 to a new implementation that caches results in an EmptyDir to not rescan the Node if a new enough cached scan is available in the cache.
The implementation was discussed and developed in stackrox/stackrox#4701, but required some minimal changes to adapt to the new location.
Limitations
Due to the fact that Scanner doesn't currently have a Duration-type environment setting, all settings for the Caching Scanner that were previously env vars are currently hardcoded (see TODO in
service.go
).This will be addressed in a follow up, ROX-16095, to keep these PR reviews short, isolated, and quick 😃
Testing Performed
I deployed this version on an OpenShift 4.12 cluster and verified that the caching functionality is still working.
As long as stackrox/stackrox/pull/5292 is not merged, manual changes need to be applied to the Collector DaemonSet to use this container.
The following changes have to be executed, after ACS has been deployed via
./deploy/openshift/deploy.sh
:Update the Collector
DaemonSet
with this additional container in spec/template/spec/containers:Afterwards, set the following env vars to shorten the rescan times for testing:
kubectl -n stackrox set env daemonsets/collector --containers="compliance" ROX_NODE_SCANNING_INTERVAL="20s" ROX_NODE_SCANNING_INTERVAL_DEVIATION="1s" ROX_NODE_SCANNING_MAX_INITIAL_WAIT="10s" LOGLEVEL="DEBUG"
Tests
echo -n "{\"CacheValidUntil\":\"0001-01-01T00:00:00Z\",\"RetryBackoffDuration\":\"10s\",\"CachedInventory\":\"\"}" > /cache/inventory-cache
. Observe a log entry on node-scanner on the next scan that it found a backoff and will wait for 10 seconds.echo -n "{\"CacheValidUntil\":\"42\",\"RetryBackoffDuration\":\"noDuration\",\"CachedInventory\":\"\"}" > /cache/inventory-cache
. Observe a failsafe where the next scan will be delayed by 300 seconds.echo -n "{\"CacheValidUntil\":\"2023-04-01T00:00:00Z\",\"RetryBackoffDuration\":\"0s\",\"CachedInventory\":\"noInventory\"}" > /cache/inventory-cache
. Observe a failsafe where the next scan will be delayed by 300 seconds.