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

Fix a bug related to unnamed objects #178

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/resources/case10_kind_field/case10_kind_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down