Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop refreshing the discovery when in uninstall mode #185

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,26 @@ func (r *ConfigurationPolicyReconciler) PeriodicallyExecConfigPolicies(

var skipLoop bool

if len(r.apiResourceList) == 0 || len(r.apiGroups) == 0 {
discoveryErr := r.refreshDiscoveryInfo()
cleanupImmediately := r.UninstallMode

// If there was an error and no API information was received, then skip the loop.
if discoveryErr != nil && (len(r.apiResourceList) == 0 || len(r.apiGroups) == 0) {
skipLoop = true
}
}
if !r.UninstallMode {
if len(r.apiResourceList) == 0 || len(r.apiGroups) == 0 {
discoveryErr := r.refreshDiscoveryInfo()

// If it's been more than 10 minutes since the last refresh, then refresh the discovery info, but ignore
// any errors since the cache can still be used. If a policy encounters an API resource type not in the
// cache, the discovery info refresh will be handled there. This periodic refresh is to account for
// deleted CRDs or strange edits to the CRD (e.g. converted it from namespaced to not).
if time.Since(r.discoveryLastRefreshed) >= waiting {
_ = r.refreshDiscoveryInfo()
}
// If there was an error and no API information was received, then skip the loop.
if discoveryErr != nil && (len(r.apiResourceList) == 0 || len(r.apiGroups) == 0) {
skipLoop = true
}
}

cleanupImmediately := r.UninstallMode
// If it's been more than 10 minutes since the last refresh, then refresh the discovery info, but ignore
// any errors since the cache can still be used. If a policy encounters an API resource type not in the
// cache, the discovery info refresh will be handled there. This periodic refresh is to account for
// deleted CRDs or strange edits to the CRD (e.g. converted it from namespaced to not).
if time.Since(r.discoveryLastRefreshed) >= waiting {
_ = r.refreshDiscoveryInfo()
}

if !r.UninstallMode {
uninstalling, crdDeleting, err := r.cleanupImmediately()
if !uninstalling && !crdDeleting && err != nil {
log.Error(err, "Failed to determine if it's time to cleanup immediately")
Expand Down