@@ -8,7 +8,11 @@ import (
88 corev1 "k8s.io/api/core/v1"
99 eventsv1 "k8s.io/api/events/v1"
1010 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12+ "k8s.io/apimachinery/pkg/runtime"
1113 "k8s.io/apimachinery/pkg/runtime/schema"
14+ kstatus "sigs.k8s.io/cli-utils/pkg/kstatus/status"
15+ ctrl "sigs.k8s.io/controller-runtime"
1216 "sigs.k8s.io/controller-runtime/pkg/client"
1317 "sigs.k8s.io/controller-runtime/pkg/event"
1418 "sigs.k8s.io/controller-runtime/pkg/predicate"
@@ -49,6 +53,24 @@ func podContainerStatusImagesChanged() predicate.Predicate {
4953 }
5054}
5155
56+ func isKStatusCurrent () predicate.Predicate {
57+ return predicate .NewPredicateFuncs (func (object client.Object ) bool {
58+ m , err := runtime .DefaultUnstructuredConverter .ToUnstructured (object )
59+ if err != nil {
60+ ctrl .Log .Error (err , "Failed to convert object to unstructured" )
61+ return false
62+ }
63+
64+ res , err := kstatus .Compute (& unstructured.Unstructured {Object : m })
65+ if err != nil {
66+ ctrl .Log .Error (err , "Failed to compute KStatus" )
67+ return false
68+ }
69+
70+ return res .Status == kstatus .CurrentStatus
71+ })
72+ }
73+
5274func ignoreCreationPredicate () predicate.Predicate {
5375 return predicate.Funcs {
5476 CreateFunc : func (e event.CreateEvent ) bool {
0 commit comments