Skip to content

Commit

Permalink
Stop refreshing the discovery when in uninstall mode
Browse files Browse the repository at this point in the history
Relates:
https://issues.redhat.com/browse/ACM-8826

Signed-off-by: mprahl <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl committed Dec 8, 2023
1 parent 56e2e70 commit d2af029
Showing 1 changed file with 16 additions and 16 deletions.
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

0 comments on commit d2af029

Please sign in to comment.