/
predicates.go
36 lines (31 loc) · 1.2 KB
/
predicates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package controllers
import (
kluctlv1 "github.com/kluctl/kluctl/v2/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
type ReconcileRequestedPredicate struct {
predicate.Funcs
}
// Update implements the default UpdateEvent filter for validating flux_utils.ReconcileRequestAnnotation changes.
func (ReconcileRequestedPredicate) Update(e event.UpdateEvent) bool {
if e.ObjectOld == nil || e.ObjectNew == nil {
return false
}
checkManualRequest := func(aname string) bool {
v1, ok1 := e.ObjectNew.GetAnnotations()[aname]
v2, ok2 := e.ObjectOld.GetAnnotations()[aname]
if !ok1 {
// if it gets removed, no need for reconciliation
// the annotation actually gets removed at the beginning of the reconciliation, which would cause an
// unnecessary reconciliation anyway.
return false
}
return ok1 != ok2 || v1 != v2
}
return checkManualRequest(kluctlv1.KluctlRequestReconcileAnnotation) ||
checkManualRequest(kluctlv1.KluctlRequestDiffAnnotation) ||
checkManualRequest(kluctlv1.KluctlRequestDeployAnnotation) ||
checkManualRequest(kluctlv1.KluctlRequestPruneAnnotation) ||
checkManualRequest(kluctlv1.KluctlRequestValidateAnnotation)
}