Skip to content

Commit 311debf

Browse files
Adjust template-sync event filter
The compliance events emitted by the template-sync controller should have priority over any created by the policy controllers. For example, in the past we had issues where a "late" compliance event from a controller would override the Pending status of a policy, and there are other template-error statuses that are emitted by the template-sync which could have the same situation. To ensure that a template-sync event is always emitted after a different compliance event, this controller should reconcile in more situations. Note that it might seem better if the template-sync controller removed the templates that have had an error, but in the case of ConfigurationPolicy, removing it can cause undesirable side-effects due to PruneObjectBehavior. Refs: - https://issues.redhat.com/browse/ACM-10858 Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent 4d7c4da commit 311debf

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

controllers/templatesync/predicate.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package templatesync
55

66
import (
7+
"strings"
8+
79
policiesv1 "open-cluster-management.io/governance-policy-propagator/api/v1"
810
"sigs.k8s.io/controller-runtime/pkg/event"
911
"sigs.k8s.io/controller-runtime/pkg/predicate"
@@ -25,7 +27,29 @@ func templatePredicates() predicate.Funcs {
2527
if hasAnyDependencies(updatedPolicy) {
2628
// if it has dependencies, and it's not currently Pending, then
2729
// it needs to re-calculate if it *should* be Pending.
28-
return updatedPolicy.Status.ComplianceState != "Pending"
30+
if updatedPolicy.Status.ComplianceState != "Pending" {
31+
return true
32+
}
33+
}
34+
35+
// Look through the history for `template-error` events. If one is
36+
// found and the "current" (0th) event is not a `template-error`, then
37+
// reconcile to determine if the template-error event needs to be
38+
// re-sent.
39+
for _, dpt := range updatedPolicy.Status.Details {
40+
if dpt == nil {
41+
continue
42+
}
43+
44+
for i, historyEvent := range dpt.History {
45+
if strings.Contains(historyEvent.Message, "template-error") {
46+
if i == 0 {
47+
break
48+
}
49+
50+
return true
51+
}
52+
}
2953
}
3054

3155
return false

0 commit comments

Comments
 (0)