@@ -129,10 +129,13 @@ func (r *HierarchyConfigReconciler) reconcile(ctx context.Context, log logr.Logg
129
129
r .updateFinalizers (ctx , log , inst , nsInst , anms )
130
130
131
131
// Sync the Hierarchy singleton with the in-memory forest.
132
- r .syncWithForest (log , nsInst , inst , deletingCRD , anms )
132
+ initial := r .syncWithForest (log , nsInst , inst , deletingCRD , anms )
133
133
134
- // Write back if anything's changed. Early-exit if we just write back exactly what we had.
135
- if updated , err := r .writeInstances (ctx , log , origHC , inst , origNS , nsInst ); ! updated || err != nil {
134
+ // Write back if anything's changed. Early-exit if we just write back exactly what we had and this
135
+ // isn't the first time we're syncing.
136
+ updated , err := r .writeInstances (ctx , log , origHC , inst , origNS , nsInst )
137
+ updated = updated || initial
138
+ if ! updated || err != nil {
136
139
return err
137
140
}
138
141
@@ -195,7 +198,7 @@ func (r *HierarchyConfigReconciler) updateFinalizers(ctx context.Context, log lo
195
198
// be able to proceed until this one is finished. While the results of the reconiliation may not be
196
199
// fully written back to the apiserver yet, each namespace is reconciled in isolation (apart from
197
200
// the in-memory forest) so this is fine.
198
- func (r * HierarchyConfigReconciler ) syncWithForest (log logr.Logger , nsInst * corev1.Namespace , inst * api.HierarchyConfiguration , deletingCRD bool , anms []string ) {
201
+ func (r * HierarchyConfigReconciler ) syncWithForest (log logr.Logger , nsInst * corev1.Namespace , inst * api.HierarchyConfiguration , deletingCRD bool , anms []string ) bool {
199
202
r .Forest .Lock ()
200
203
defer r .Forest .Unlock ()
201
204
ns := r .Forest .Get (inst .ObjectMeta .Namespace )
@@ -214,7 +217,7 @@ func (r *HierarchyConfigReconciler) syncWithForest(log logr.Logger, nsInst *core
214
217
// for this namespace to be synced.
215
218
r .syncSubnamespaceParent (log , inst , nsInst , ns )
216
219
r .syncParent (log , inst , ns )
217
- r .markExisting (log , ns )
220
+ initial := r .markExisting (log , ns )
218
221
219
222
// Sync other spec and spec-like info
220
223
r .syncAnchors (log , ns , anms )
@@ -226,6 +229,8 @@ func (r *HierarchyConfigReconciler) syncWithForest(log logr.Logger, nsInst *core
226
229
227
230
// Sync the tree labels. This should go last since it can depend on the conditions.
228
231
r .syncLabel (log , nsInst , ns )
232
+
233
+ return initial
229
234
}
230
235
231
236
// syncExternalNamespace sets external tree labels to the namespace in the forest
@@ -315,15 +320,17 @@ func (r *HierarchyConfigReconciler) syncSubnamespaceParent(log logr.Logger, inst
315
320
316
321
// markExisting marks the namespace as existing. If this is the first time we're reconciling this namespace,
317
322
// mark all possible relatives as being affected since they may have been waiting for this namespace.
318
- func (r * HierarchyConfigReconciler ) markExisting (log logr.Logger , ns * forest.Namespace ) {
319
- if ns .SetExists () {
320
- log .Info ("Reconciling new namespace" )
321
- r .enqueueAffected (log , "relative of newly synced/created namespace" , ns .RelativesNames ()... )
322
- if ns .IsSub {
323
- r .enqueueAffected (log , "parent of the newly synced/created subnamespace" , ns .Parent ().Name ())
324
- r .sar .enqueue (log , ns .Name (), ns .Parent ().Name (), "the missing subnamespace is found" )
325
- }
323
+ func (r * HierarchyConfigReconciler ) markExisting (log logr.Logger , ns * forest.Namespace ) bool {
324
+ if ! ns .SetExists () {
325
+ return false
326
+ }
327
+ log .Info ("Reconciling new namespace" )
328
+ r .enqueueAffected (log , "relative of newly synced/created namespace" , ns .RelativesNames ()... )
329
+ if ns .IsSub {
330
+ r .enqueueAffected (log , "parent of the newly synced/created subnamespace" , ns .Parent ().Name ())
331
+ r .sar .enqueue (log , ns .Name (), ns .Parent ().Name (), "the missing subnamespace is found" )
326
332
}
333
+ return true
327
334
}
328
335
329
336
func (r * HierarchyConfigReconciler ) syncParent (log logr.Logger , inst * api.HierarchyConfiguration , ns * forest.Namespace ) {
0 commit comments