Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit cc57d6c

Browse files
authored
Merge pull request #1163 from adrianludwin/reconcile-once
Ensure all objects are reconciled at least once
2 parents 6e8c83f + 36f9190 commit cc57d6c

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

incubator/hnc/internal/reconcilers/hierarchy_config.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ func (r *HierarchyConfigReconciler) reconcile(ctx context.Context, log logr.Logg
129129
r.updateFinalizers(ctx, log, inst, nsInst, anms)
130130

131131
// 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)
133133

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 {
136139
return err
137140
}
138141

@@ -195,7 +198,7 @@ func (r *HierarchyConfigReconciler) updateFinalizers(ctx context.Context, log lo
195198
// be able to proceed until this one is finished. While the results of the reconiliation may not be
196199
// fully written back to the apiserver yet, each namespace is reconciled in isolation (apart from
197200
// 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 {
199202
r.Forest.Lock()
200203
defer r.Forest.Unlock()
201204
ns := r.Forest.Get(inst.ObjectMeta.Namespace)
@@ -214,7 +217,7 @@ func (r *HierarchyConfigReconciler) syncWithForest(log logr.Logger, nsInst *core
214217
// for this namespace to be synced.
215218
r.syncSubnamespaceParent(log, inst, nsInst, ns)
216219
r.syncParent(log, inst, ns)
217-
r.markExisting(log, ns)
220+
initial := r.markExisting(log, ns)
218221

219222
// Sync other spec and spec-like info
220223
r.syncAnchors(log, ns, anms)
@@ -226,6 +229,8 @@ func (r *HierarchyConfigReconciler) syncWithForest(log logr.Logger, nsInst *core
226229

227230
// Sync the tree labels. This should go last since it can depend on the conditions.
228231
r.syncLabel(log, nsInst, ns)
232+
233+
return initial
229234
}
230235

231236
// syncExternalNamespace sets external tree labels to the namespace in the forest
@@ -315,15 +320,17 @@ func (r *HierarchyConfigReconciler) syncSubnamespaceParent(log logr.Logger, inst
315320

316321
// markExisting marks the namespace as existing. If this is the first time we're reconciling this namespace,
317322
// 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")
326332
}
333+
return true
327334
}
328335

329336
func (r *HierarchyConfigReconciler) syncParent(log logr.Logger, inst *api.HierarchyConfiguration, ns *forest.Namespace) {

0 commit comments

Comments
 (0)