-
Notifications
You must be signed in to change notification settings - Fork 20
feat: skip creation of empty work object #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
c7a38e5 to
64e91e5
Compare
| } | ||
| if len(simpleManifests) == 0 { | ||
| klog.V(2).InfoS("the snapshot contains no resource to apply either because of override or enveloped resources", "snapshot", klog.KObj(snapshot)) | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confused: from the comments, it seems that crp always depends on work to populate the status of the placement. And now, for CRP w/o any resources, we do not generate a work obj, what's gonna happen on CRP status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRP Status will still be available. We are thinking of updating UX that will change CRP status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without a work, the binding status will not be updated thus CRP reconcile not triggered, I am not entirely sure how it will work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the changes I implemented, workUpdated will be false here.
Since it is false, we will set the binding status.
Within the function setBindingStatus, we check to see the apply strategy and set the conditions here.
Since there are no works, the default for the condition will be set which is True. This is where we can update the UX interface to show whether the resources were selected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see two scenarios where workUpdated can be true in this case:
- With an older version of hub-agent without your change, an empty work will be generated and after upgrading the image with your change, that empty work object will be deleted by code below on line 546-562 and workUpdated becomes true.
- When there are multiple resourceSnapshots generated or there's a configmap-wrapped resource, there will be other work obj generated and thus workUpdated also becomes true.
Could you please verify these two cases and add tests?
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
| } | ||
| if len(simpleManifests) == 0 { | ||
| klog.V(2).InfoS("the snapshot contains no resource to apply either because of override or enveloped resources", "snapshot", klog.KObj(snapshot)) | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see two scenarios where workUpdated can be true in this case:
- With an older version of hub-agent without your change, an empty work will be generated and after upgrading the image with your change, that empty work object will be deleted by code below on line 546-562 and workUpdated becomes true.
- When there are multiple resourceSnapshots generated or there's a configmap-wrapped resource, there will be other work obj generated and thus workUpdated also becomes true.
Could you please verify these two cases and add tests?
zhiying-lin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@britaniar could you please update the PR description to show me the final crp status condition when no resources are selected? We need to agree on the user experience/api first . I remember ryan mentioned that cx is confused by the applied/available true status. btw, wantong is working on updating the CRP conditions and code may have conflicts.
83e637e to
3664bbb
Compare
| case rpsSetCondTypeCounter[i][condition.FalseConditionStatus] > 0: | ||
| // There is at least one False condition of the given type being set on the per cluster placement statuses. | ||
| crp.SetConditions(i.FalseClusterResourcePlacementCondition(crp.Generation, rpsSetCondTypeCounter[i][condition.FalseConditionStatus])) | ||
| if len(crp.Status.SelectedResources) == 0 && i == condition.AppliedCondition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current behavior is when no resource is selected, the work obj still gets created, and all clusters as well as the crp shows Applied/Available to true. We are changing this behavior. Is this what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we want to change it from it being Applied/Available is true because the cx gets confused.
zhiying-lin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i recall that why we treat the applied & available originally as true. There will be a case, cx first applied a namespace, and then he/she wants to delete this namespace in all members but keeps the crp.
CRP still needs to apply the resources (delete the resources). I'm thinking of changing the applied & available reason to something else, instead of marking them as false, and it also simplifies our alert.
59dbd2b to
ff84430
Compare
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
keep available/applied condition true and update CRP status message/reason Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
zhiying-lin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's split the PRs into 6 smaller PRs and add tests to catch the regression:
- Fix the bug to track the deleting works, set the binding applied condition is false when work is still in the deleting state. https://github.com/kubefleet-dev/kubefleet/blob/main/pkg/controllers/workgenerator/controller.go#L1010
- Test to see what's the behavior our drift/reportDiff feature when no resource are selected. Add tests if missing.
- Add e2e tests when resource is not selected
- update code to not create work when resource is not selected
- update the work binding condition message & reason when resource is not selected
- update the crp condition message & reason when resource is not selected
| } | ||
| case condition.AppliedCondition: | ||
| if len(crp.Status.SelectedResources) == 0 { | ||
| cond.Message = "Previous resources are deleted. No new resources are selected for the placement" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``
| cond.Message = "Previous resources are deleted. No new resources are selected for the placement" | |
| cond.Message = "No new resources are selected for the placement and deleted applied resources if exists" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change the reason to "NoResourcesSelectedReason" too?
| case condition.AvailableCondition: | ||
| if len(crp.Status.SelectedResources) == 0 { | ||
| cond.Reason = condition.NoResourcesSelectedReason | ||
| cond.Message = "No new resources are selected for the placement. Please update crp to select new resources" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cond.Message = "No new resources are selected for the placement. Please update crp to select new resources" | |
| cond.Message = "No new resources are applied for the placement" |
cx can create the resources instead of updating crp.
| if syncErr == nil { | ||
| // generate and apply the workUpdated works if we have all the works | ||
| overrideSucceeded, workUpdated, syncErr = r.syncAllWork(ctx, &resourceBinding, works, &cluster) | ||
| overrideSucceeded, workUpdated, resourcesSelected, syncErr = r.syncAllWork(ctx, &resourceBinding, works, &cluster) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please test drift detection/ report diff feature when no resources are selected? i'm not sure if we reply on this empty work.
Description of your changes
Fixes #
I have: skipped creating an empty work object when no resources have been selected.
make reviewableto ensure this PR is ready for review.How has this code been tested
Special notes for your reviewer
The CRP controller relies exclusively on work status to populate the "applied" condition on CRP. There is a special case that no resource is selected. Currently, the work generator creates an empty work object to accommodate this behavior.
New UX outcome: