Skip to content

Commit

Permalink
feat: add work created condition in the binding (Azure#742)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Zhang <[email protected]>
  • Loading branch information
ryanzhang-oss and Ryan Zhang authored Apr 2, 2024
1 parent e18a9e0 commit a4dc794
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
17 changes: 16 additions & 1 deletion pkg/controllers/workgenerator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,35 @@ 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),
Reason: syncWorkFailedReason,
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{
Expand Down Expand Up @@ -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(),
}
}
Expand Down
38 changes: 31 additions & 7 deletions pkg/controllers/workgenerator/controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a4dc794

Please sign in to comment.