Skip to content
Open
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: 10 additions & 1 deletion controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@

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

for index, objectT := range plc.Spec.ObjectTemplates {
// Check if any object template uses objectSelector - pruning should be disabled during
// normal reconciliation to prevent deletion of objects that stop matching the selector
if !skipCleanupChildObjects && objectT.ObjectSelector != nil {
skipCleanupChildObjects = true
log.V(2).Info("Disabling object cleanup during reconciliation because objectSelector is in use")

Check failure on line 1038 in controllers/configurationpolicy_controller.go

View workflow job for this annotation

GitHub Actions / Preflight Tests

only cuddled expressions if assigning variable or using from line above (wsl)
}

nsNameToResults := map[string]objectTmplEvalResult{}

var resolverToUse *templates.TemplateResolver
Expand Down
Loading