@@ -44,6 +44,7 @@ import (
44
44
"sigs.k8s.io/controller-runtime/pkg/client"
45
45
"sigs.k8s.io/controller-runtime/pkg/controller"
46
46
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
47
+ "sigs.k8s.io/controller-runtime/pkg/event"
47
48
"sigs.k8s.io/controller-runtime/pkg/handler"
48
49
"sigs.k8s.io/controller-runtime/pkg/predicate"
49
50
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -113,11 +114,40 @@ type KustomizationReconcilerOptions struct {
113
114
RateLimiter workqueue.TypedRateLimiter [reconcile.Request ]
114
115
}
115
116
117
+ type kustomizationReadyChangePredicate struct {
118
+ predicate.Funcs
119
+ }
120
+
121
+ func (kustomizationReadyChangePredicate ) Update (e event.UpdateEvent ) bool {
122
+ if e .ObjectNew == nil || e .ObjectOld == nil {
123
+ return false
124
+ }
125
+
126
+ newKs , ok := e .ObjectNew .(* kustomizev1.Kustomization )
127
+ if ! ok {
128
+ return false
129
+ }
130
+ oldKs , ok := e .ObjectOld .(* kustomizev1.Kustomization )
131
+ if ! ok {
132
+ return false
133
+ }
134
+
135
+ if ! conditions .IsReady (newKs ) {
136
+ return false
137
+ }
138
+ if ! conditions .IsReady (oldKs ) {
139
+ return true
140
+ }
141
+
142
+ return oldKs .Status .LastAppliedRevision != newKs .Status .LastAppliedRevision
143
+ }
144
+
116
145
func (r * KustomizationReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , opts KustomizationReconcilerOptions ) error {
117
146
const (
118
147
ociRepositoryIndexKey string = ".metadata.ociRepository"
119
148
gitRepositoryIndexKey string = ".metadata.gitRepository"
120
149
bucketIndexKey string = ".metadata.bucket"
150
+ ksDependencyIndexKey string = ".metadata.dependsOn"
121
151
)
122
152
123
153
// Index the Kustomizations by the OCIRepository references they (may) point at.
@@ -138,6 +168,12 @@ func (r *KustomizationReconciler) SetupWithManager(ctx context.Context, mgr ctrl
138
168
return fmt .Errorf ("failed setting index fields: %w" , err )
139
169
}
140
170
171
+ // Index the Kustomizations by the dependsOn references they (may) point at.
172
+ if err := mgr .GetCache ().IndexField (ctx , & kustomizev1.Kustomization {}, ksDependencyIndexKey ,
173
+ r .indexDependsOn ()); err != nil {
174
+ return fmt .Errorf ("failed setting index fields: %w" , err )
175
+ }
176
+
141
177
r .requeueDependency = opts .DependencyRequeueInterval
142
178
r .statusManager = fmt .Sprintf ("gotk-%s" , r .ControllerName )
143
179
r .artifactFetchRetries = opts .HTTPRetry
@@ -146,6 +182,11 @@ func (r *KustomizationReconciler) SetupWithManager(ctx context.Context, mgr ctrl
146
182
For (& kustomizev1.Kustomization {}, builder .WithPredicates (
147
183
predicate .Or (predicate.GenerationChangedPredicate {}, predicates.ReconcileRequestedPredicate {}),
148
184
)).
185
+ Watches (
186
+ & kustomizev1.Kustomization {},
187
+ handler .EnqueueRequestsFromMapFunc (r .requestsForDependentsWaiting (ksDependencyIndexKey )),
188
+ builder .WithPredicates (kustomizationReadyChangePredicate {}),
189
+ ).
149
190
Watches (
150
191
& sourcev1b2.OCIRepository {},
151
192
handler .EnqueueRequestsFromMapFunc (r .requestsForRevisionChangeOf (ociRepositoryIndexKey )),
@@ -271,7 +312,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
271
312
if len (obj .Spec .DependsOn ) > 0 {
272
313
if err := r .checkDependencies (ctx , obj , artifactSource ); err != nil {
273
314
conditions .MarkFalse (obj , meta .ReadyCondition , meta .DependencyNotReadyReason , "%s" , err )
274
- msg := fmt .Sprintf ("Dependencies do not meet ready condition, retrying in %s" , r .requeueDependency .String ())
315
+ msg := fmt .Sprintf ("Dependencies do not meet ready condition, retrying in %s: %s " , r .requeueDependency .String (), err )
275
316
log .Info (msg )
276
317
r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo , msg , nil )
277
318
return ctrl.Result {RequeueAfter : r .requeueDependency }, nil
0 commit comments