diff --git a/pkg/controllers/workgenerator/controller.go b/pkg/controllers/workgenerator/controller.go index dac2cb6ed..0511dc143 100644 --- a/pkg/controllers/workgenerator/controller.go +++ b/pkg/controllers/workgenerator/controller.go @@ -115,6 +115,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req controllerruntime.Reques if syncErr != nil { klog.ErrorS(syncErr, "Failed to sync all the works", "resourceBinding", bindingRef) + // TODO: remove the deprecated "resourceBound" condition when we switch to the new condition model resourceBinding.SetConditions(metav1.Condition{ Status: metav1.ConditionFalse, Type: string(fleetv1beta1.ResourceBindingBound), @@ -122,13 +123,27 @@ func (r *Reconciler) Reconcile(ctx context.Context, req controllerruntime.Reques Message: syncErr.Error(), ObservedGeneration: resourceBinding.Generation, }) + resourceBinding.SetConditions(metav1.Condition{ + Status: metav1.ConditionFalse, + Type: string(fleetv1beta1.ResourceBindingWorkCreated), + Reason: syncWorkFailedReason, + Message: syncErr.Error(), + ObservedGeneration: resourceBinding.Generation, + }) } else { + // TODO: remove the deprecated "resourceBound" condition when we switch to the new condition model resourceBinding.SetConditions(metav1.Condition{ Status: metav1.ConditionTrue, Type: string(fleetv1beta1.ResourceBindingBound), Reason: allWorkSyncedReason, ObservedGeneration: resourceBinding.Generation, }) + resourceBinding.SetConditions(metav1.Condition{ + Status: metav1.ConditionTrue, + Type: string(fleetv1beta1.ResourceBindingWorkCreated), + Reason: allWorkSyncedReason, + ObservedGeneration: resourceBinding.Generation, + }) if workUpdated { // revert the applied condition if we made any changes to the work resourceBinding.SetConditions(metav1.Condition{ @@ -568,7 +583,7 @@ func buildAllWorkAvailableCondition(works map[string]*fleetv1beta1.Work, binding Status: metav1.ConditionFalse, Type: string(fleetv1beta1.ResourceBindingAvailable), Reason: workNotAvailableReason, - Message: fmt.Sprintf("work object %s is not available", notAvailableWork), + Message: fmt.Sprintf("Work object %s is not available", notAvailableWork), ObservedGeneration: binding.GetGeneration(), } } diff --git a/pkg/controllers/workgenerator/controller_integration_test.go b/pkg/controllers/workgenerator/controller_integration_test.go index 5e332e47a..f5110e87e 100644 --- a/pkg/controllers/workgenerator/controller_integration_test.go +++ b/pkg/controllers/workgenerator/controller_integration_test.go @@ -134,11 +134,17 @@ var _ = Describe("Test Work Generator Controller", func() { Reason: syncWorkFailedReason, ObservedGeneration: binding.GetGeneration(), }, + { + Type: string(fleetv1beta1.ResourceBindingWorkCreated), + Status: metav1.ConditionFalse, + Reason: syncWorkFailedReason, + ObservedGeneration: binding.GetGeneration(), + }, }, } diff := cmp.Diff(wantStatus, binding.Status, ignoreConditionOption) Expect(diff).Should(BeEmpty(), fmt.Sprintf("binding(%s) mismatch (-want +got):\n%s", binding.Name, diff)) - Expect(binding.GetCondition(string(fleetv1beta1.ResourceBindingBound)).Message).Should(ContainSubstring("resource snapshots are still being created for the masterResourceSnapshot")) + Expect(binding.GetCondition(string(fleetv1beta1.ResourceBindingWorkCreated)).Message).Should(ContainSubstring("resource snapshots are still being created for the masterResourceSnapshot")) // create the second resource snapshot secondSnapshot := generateResourceSnapshot(1, 2, 1, [][]byte{ testClonesetCRD, testNameSpace, testCloneset, @@ -215,9 +221,9 @@ var _ = Describe("Test Work Generator Controller", func() { if err := k8sClient.Get(ctx, types.NamespacedName{Name: binding.Name}, binding); err != nil { return false } - // only check the bound status as the applied status reason changes depends on where the reconcile logic is + // only check the work created status as the applied status reason changes depends on where the reconcile logic is return condition.IsConditionStatusTrue( - meta.FindStatusCondition(binding.Status.Conditions, string(fleetv1beta1.ResourceBindingBound)), binding.GetGeneration()) + meta.FindStatusCondition(binding.Status.Conditions, string(fleetv1beta1.ResourceBindingWorkCreated)), binding.GetGeneration()) }, timeout, interval).Should(BeTrue(), fmt.Sprintf("binding(%s) condition should be true", binding.Name)) // check the work is created by now work := fleetv1beta1.Work{} @@ -428,9 +434,9 @@ var _ = Describe("Test Work Generator Controller", func() { if binding.GetGeneration() <= 1 { return false } - // only check the bound status as the applied status reason changes depends on where the reconcile logic is + // only check the work created status as the applied status reason changes depends on where the reconcile logic is return condition.IsConditionStatusTrue( - meta.FindStatusCondition(binding.Status.Conditions, string(fleetv1beta1.ResourceBindingBound)), binding.GetGeneration()) + meta.FindStatusCondition(binding.Status.Conditions, string(fleetv1beta1.ResourceBindingWorkCreated)), binding.GetGeneration()) }, timeout, interval).Should(BeTrue(), fmt.Sprintf("binding(%s) condition should be true", binding.Name)) By(fmt.Sprintf("resource binding %s is reconciled", binding.Name)) // check the work that contains none enveloped object is updated @@ -533,9 +539,9 @@ var _ = Describe("Test Work Generator Controller", func() { if binding.GetGeneration() <= 1 { return false } - // only check the bound status as the applied status reason changes depends on where the reconcile logic is + // only check the work created status as the applied status reason changes depends on where the reconcile logic is return condition.IsConditionStatusTrue( - meta.FindStatusCondition(binding.Status.Conditions, string(fleetv1beta1.ResourceBindingBound)), binding.GetGeneration()) + meta.FindStatusCondition(binding.Status.Conditions, string(fleetv1beta1.ResourceBindingWorkCreated)), binding.GetGeneration()) }, timeout, interval).Should(BeTrue(), fmt.Sprintf("binding(%s) condition should be true", binding.Name)) By(fmt.Sprintf("resource binding %s is reconciled", binding.Name)) // check the enveloped work is deleted @@ -868,6 +874,12 @@ func verifyBindingStatusSyncedNotApplied(binding *fleetv1beta1.ClusterResourceBi Reason: allWorkSyncedReason, ObservedGeneration: binding.GetGeneration(), }, + { + Type: string(fleetv1beta1.ResourceBindingWorkCreated), + Status: metav1.ConditionTrue, + Reason: allWorkSyncedReason, + ObservedGeneration: binding.GetGeneration(), + }, { Status: metav1.ConditionFalse, Type: string(fleetv1beta1.ResourceBindingApplied), @@ -891,6 +903,12 @@ func verifyBindStatusAppliedNotAvailable(binding *fleetv1beta1.ClusterResourceBi Reason: allWorkSyncedReason, ObservedGeneration: binding.GetGeneration(), }, + { + Type: string(fleetv1beta1.ResourceBindingWorkCreated), + Status: metav1.ConditionTrue, + Reason: allWorkSyncedReason, + ObservedGeneration: binding.GetGeneration(), + }, { Type: string(fleetv1beta1.ResourceBindingApplied), Status: metav1.ConditionTrue, @@ -920,6 +938,12 @@ func verifyBindStatusAvail(binding *fleetv1beta1.ClusterResourceBinding) { Reason: allWorkSyncedReason, ObservedGeneration: binding.GetGeneration(), }, + { + Type: string(fleetv1beta1.ResourceBindingWorkCreated), + Status: metav1.ConditionTrue, + Reason: allWorkSyncedReason, + ObservedGeneration: binding.GetGeneration(), + }, { Type: string(fleetv1beta1.ResourceBindingApplied), Status: metav1.ConditionTrue,