diff --git a/controllers/configurationpolicy_controller.go b/controllers/configurationpolicy_controller.go index 1186853b..f933f6b3 100644 --- a/controllers/configurationpolicy_controller.go +++ b/controllers/configurationpolicy_controller.go @@ -1529,6 +1529,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 } } @@ -2771,6 +2778,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