Skip to content
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

feat: enable work generator to process apply strategy updates + DiffReported condition #1016

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

michaelawyu
Copy link
Contributor

Description of your changes

This PR:

a) fixes the issue where work generator will not refresh apply strategies; and
b) enables work generator to process DiffReported condition

I have:

  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

  • Unit tests
  • Integration tests

Special notes for your reviewer

E2E tests can only be added when the new work applier is enabled.

@@ -700,15 +703,16 @@ func (r *Reconciler) upsertWork(ctx context.Context, newWork, existingWork *flee
} else {
// we already checked the label in fetchAllResourceSnapShots function so no need to check again
resourceIndex, _ := labels.ExtractResourceIndexFromClusterResourceSnapshot(resourceSnapshot)
if workResourceIndex == resourceIndex {
// no need to do anything if the work is generated from the same resource/override snapshots
if workResourceIndex == resourceIndex && equality.Semantic.DeepEqual(existingWork.Spec.ApplyStrategy, newWork.Spec.ApplyStrategy) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also check applyStrategy in the areAllWorkSynced() function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is actually a tricky one; to avoid apply strategy inconsistencies the refresh has to be handled before the check. I will some edits

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this after we did the update of the applyStrategy first regardless?

pkg/controllers/workgenerator/controller.go Show resolved Hide resolved
pkg/utils/common.go Outdated Show resolved Hide resolved
Comment on lines +1819 to +1829
It("can update work status", func() {
work := retrieveWork(memberClusterNamespaceName, fmt.Sprintf(placementv1beta1.FirstWorkNameFmt, testCRPName))

diffReportedCond := &metav1.Condition{
Type: string(placementv1beta1.WorkConditionTypeDiffReported),
Status: metav1.ConditionTrue,
Reason: string(workapplier.ManifestProcessingReportDiffResultTypeNoDiffFound),
ObservedGeneration: work.GetGeneration(),
}
refreshWorkStatus(work, nil, nil, diffReportedCond, nil)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we won't need this (which simulated a behavior of another controller) if we explicitly set the applied to be false ourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ryan! Part of the code tests the status populator, which is why the condition is being set (summarizing all DiffReported conditions from work objects).

if updateErr := errs.Wait(); updateErr != nil {
return false, false, updateErr
}

// the hash256 function can can handle empty list https://go.dev/play/p/_4HW17fooXM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the hash256 function can can handle empty list https://go.dev/play/p/_4HW17fooXM
// the hash256 function can handle empty list https://go.dev/play/p/_4HW17fooXM

if err != nil {
return err
}
if updated {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will revert the applied condition on the binding. It seems that it's fine but please think through.

@@ -700,15 +703,16 @@ func (r *Reconciler) upsertWork(ctx context.Context, newWork, existingWork *flee
} else {
// we already checked the label in fetchAllResourceSnapShots function so no need to check again
resourceIndex, _ := labels.ExtractResourceIndexFromClusterResourceSnapshot(resourceSnapshot)
if workResourceIndex == resourceIndex {
// no need to do anything if the work is generated from the same resource/override snapshots
if workResourceIndex == resourceIndex && equality.Semantic.DeepEqual(existingWork.Spec.ApplyStrategy, newWork.Spec.ApplyStrategy) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this after we did the update of the applyStrategy first regardless?

if existingWork.Annotations[fleetv1beta1.ParentResourceOverrideSnapshotHashAnnotation] == newWork.Annotations[fleetv1beta1.ParentResourceOverrideSnapshotHashAnnotation] &&
existingWork.Annotations[fleetv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation] == newWork.Annotations[fleetv1beta1.ParentClusterResourceOverrideSnapshotHashAnnotation] {
klog.V(2).InfoS("Work is associated with the desired resource/override snapshots", "existingROHash", existingWork.Annotations[fleetv1beta1.ParentResourceOverrideSnapshotHashAnnotation],
klog.V(2).InfoS("Work is associated with the desired resource/override snapshots and apply strategy", "existingROHash", existingWork.Annotations[fleetv1beta1.ParentResourceOverrideSnapshotHashAnnotation],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +934 to +936
// In the case where ReportDiff apply strategy is used, work applier will no longer update
// Applied condition on Work objects; since existing Applied conditions will all become stale,
// this function will return a False Applied condition.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this comment?

// in the status, as appropriate; the DiffReported condition will not be updated.
// b) If the currently active apply strategy is ReportDiff, the work generator will update
// the DiffReported condition in the status, plus the details about diffed placements;
// the Applied condition will always be set to False, despite the fact that the work applier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is " the Applied condition will always be set to False" done explicitly?

wantUpdated bool
wantApplyStrategy *fleetv1beta1.ApplyStrategy
}{
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a diff test case? the work has something but the binding has something else?

updateRolloutStartedGeneration(&clusterResourceBinding)
})

It("should update apply strategy on the work object", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not continue to check the binding status too?

Eventually(applyStrategyUpdatedActual, timeout, interval).Should(Succeed(), "Failed to create expected work object")
})

AfterAll(func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not reuse this AfterAll between those ITs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants