diff --git a/controllers/configurationpolicy_controller.go b/controllers/configurationpolicy_controller.go index 49a4c7d2..dcc51a73 100644 --- a/controllers/configurationpolicy_controller.go +++ b/controllers/configurationpolicy_controller.go @@ -1525,6 +1525,13 @@ func (r *ConfigurationPolicyReconciler) handleObjects( if len(objNames) == 0 { exists = false + } else if len(objNames) == 1 { + // If the object couldn't be retrieved, this will be handled later on. + existingObj, _ = getObject( + objDetails.isNamespaced, namespace, objNames[0], mapping.Resource, r.TargetK8sDynamicClient, + ) + + exists = existingObj != nil } } @@ -2746,6 +2753,10 @@ func (r *ConfigurationPolicyReconciler) setEvaluatedObject( func (r *ConfigurationPolicyReconciler) alreadyEvaluated( policy *policyv1.ConfigurationPolicy, currentObject *unstructured.Unstructured, ) (evaluated bool, compliant bool) { + if policy == nil || currentObject == nil { + return false, false + } + loadedPolicyMap, loaded := r.processedPolicyCache.Load(policy.GetUID()) if !loaded { return false, false diff --git a/test/resources/case10_kind_field/case10_kind_check.yaml b/test/resources/case10_kind_field/case10_kind_check.yaml index eabf442c..43804783 100644 --- a/test/resources/case10_kind_field/case10_kind_check.yaml +++ b/test/resources/case10_kind_field/case10_kind_check.yaml @@ -6,6 +6,13 @@ spec: remediationAction: inform # will be overridden by remediationAction in parent policy severity: low object-templates: + # The first object template is ensure no regression for https://issues.redhat.com/browse/ACM-8731 + - complianceType: musthave + objectDefinition: + apiVersion: v1 + kind: Namespace + metadata: + name: default - complianceType: musthave objectDefinition: apiVersion: v1