Skip to content

Commit 1babbed

Browse files
committed
fix: Disable pruning during reconciliation when objectSelector is used
Fixes issue where objects could be updated then deleted when the update causes them to stop matching the objectSelector. Objects are still cleaned up when the policy is deleted. ref: https://issues.redhat.com/browse/ACM-26186 Signed-off-by: Dale Haiducek <[email protected]>
1 parent 34be92a commit 1babbed

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

controllers/configurationpolicy_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ func (r *ConfigurationPolicyReconciler) shouldEvaluatePolicy(
551551

552552
// cleanUpChildObjects conditionally removed child objects that are no longer referenced in the
553553
// `newRelated` list, compared to what is currently in the policy. It does not delete anything in
554-
// inform mode, and it obeys the pruneObjectBehavior setting.
554+
// inform mode, and it obeys the pruneObjectBehavior setting. During normal reconciliation, cleanup
555+
// is skipped when any object template uses objectSelector to prevent deletion of objects that stop
556+
// matching the selector after being updated. Cleanup still occurs when the policy itself is deleted.
555557
func (r *ConfigurationPolicyReconciler) cleanUpChildObjects(
556558
plc *policyv1.ConfigurationPolicy, newRelated []policyv1.RelatedObject, usingWatch bool,
557559
) []string {
@@ -1029,6 +1031,13 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc *policyv1.Conf
10291031
var skipCleanupChildObjects bool
10301032

10311033
for index, objectT := range plc.Spec.ObjectTemplates {
1034+
// Check if any object template uses objectSelector - pruning should be disabled during
1035+
// normal reconciliation to prevent deletion of objects that stop matching the selector
1036+
if !skipCleanupChildObjects && objectT.ObjectSelector != nil {
1037+
skipCleanupChildObjects = true
1038+
log.V(2).Info("Disabling object cleanup during reconciliation because objectSelector is in use")
1039+
}
1040+
10321041
nsNameToResults := map[string]objectTmplEvalResult{}
10331042

10341043
var resolverToUse *templates.TemplateResolver

0 commit comments

Comments
 (0)