From 0affae76101df2442ae796a70f20ff7fbcda1200 Mon Sep 17 00:00:00 2001 From: mprahl Date: Fri, 8 Dec 2023 10:15:35 -0500 Subject: [PATCH] Stop refreshing the discovery when in uninstall mode Relates: https://issues.redhat.com/browse/ACM-8826 Signed-off-by: mprahl --- controllers/configurationpolicy_controller.go | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/controllers/configurationpolicy_controller.go b/controllers/configurationpolicy_controller.go index 02e262c1..23f626ee 100644 --- a/controllers/configurationpolicy_controller.go +++ b/controllers/configurationpolicy_controller.go @@ -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")