From 78db57090f99114882a1a9eb6cddce5bcdc97d31 Mon Sep 17 00:00:00 2001 From: Ryan Zhang Date: Thu, 24 Oct 2024 20:06:28 -0700 Subject: [PATCH] only move on if the binding is already synced --- pkg/controllers/workgenerator/controller.go | 5 +++++ pkg/controllers/workgenerator/controller_integration_test.go | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/workgenerator/controller.go b/pkg/controllers/workgenerator/controller.go index 0bb5c17db..e611a6f75 100644 --- a/pkg/controllers/workgenerator/controller.go +++ b/pkg/controllers/workgenerator/controller.go @@ -506,6 +506,11 @@ func (r *Reconciler) syncAllWork(ctx context.Context, resourceBinding *fleetv1be // areAllWorkSynced checks if all the works are synced with the resource binding. func areAllWorkSynced(existingWorks map[string]*fleetv1beta1.Work, resourceBinding *fleetv1beta1.ClusterResourceBinding, _, _ string) bool { + syncedCondition := resourceBinding.GetCondition(string(fleetv1beta1.ResourceBindingWorkSynchronized)) + if !condition.IsConditionStatusTrue(syncedCondition, resourceBinding.Generation) { + // The binding has to be synced first before we can check the works + return false + } // TODO: check resourceOverrideSnapshotHash and clusterResourceOverrideSnapshotHash after all the work has the ParentResourceOverrideSnapshotHashAnnotation and ParentClusterResourceOverrideSnapshotHashAnnotation resourceSnapshotName := resourceBinding.Spec.ResourceSnapshotName for _, work := range existingWorks { diff --git a/pkg/controllers/workgenerator/controller_integration_test.go b/pkg/controllers/workgenerator/controller_integration_test.go index f087ea05b..ee3c34ff5 100644 --- a/pkg/controllers/workgenerator/controller_integration_test.go +++ b/pkg/controllers/workgenerator/controller_integration_test.go @@ -1405,7 +1405,6 @@ var _ = Describe("Test Work Generator Controller", func() { // binding should have a finalizer Expect(k8sClient.Get(ctx, types.NamespacedName{Name: binding.Name}, binding)).Should(Succeed()) Expect(len(binding.Finalizers)).Should(Equal(1)) - Eventually(func() string { Expect(k8sClient.Get(ctx, types.NamespacedName{Name: binding.Name}, binding)).Should(Succeed()) wantStatus := placementv1beta1.ResourceBindingStatus{