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

fix: update policy snapshot status in cases where only the observed CRP generation changes #569

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions pkg/scheduler/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,13 @@ func (f *framework) updatePolicySnapshotStatusFromBindings(
) error {
policyRef := klog.KObj(policy)

// Retrieve the corresponding CRP generation.
observedCRPGeneration, err := annotations.ExtractObservedCRPGenerationFromPolicySnapshot(policy)
if err != nil {
klog.ErrorS(err, "Failed to retrieve CRP generation from annoation", "clusterSchedulingPolicySnapshot", policyRef)
return controller.NewUnexpectedBehaviorError(err)
}

// Prepare new scheduling decisions.
newDecisions := newSchedulingDecisionsFromBindings(f.maxUnselectedClusterDecisionCount, notPicked, filtered, existing...)
// Prepare new scheduling condition.
Expand All @@ -704,18 +711,16 @@ func (f *framework) updatePolicySnapshotStatusFromBindings(
// Compare the new decisions + condition with the old ones.
currentDecisions := policy.Status.ClusterDecisions
currentCondition := meta.FindStatusCondition(policy.Status.Conditions, string(placementv1beta1.PolicySnapshotScheduled))
if equalDecisions(currentDecisions, newDecisions) && condition.EqualCondition(currentCondition, &newCondition) {
if observedCRPGeneration == policy.Status.ObservedCRPGeneration &&
Copy link
Contributor

Choose a reason for hiding this comment

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

when will we hit the case that the decision/condition doesn't change but the CRP's generation has changed (selector changed)

equalDecisions(currentDecisions, newDecisions) &&
condition.EqualCondition(currentCondition, &newCondition) {
// Skip if there is no change in decisions and conditions.
klog.InfoS(
"No change in scheduling decisions and condition, and the observed CRP generation remains the same",
"clusterSchedulingPolicySnapshot", policyRef)
return nil
}

// Retrieve the corresponding CRP generation.
observedCRPGeneration, err := annotations.ExtractObservedCRPGenerationFromPolicySnapshot(policy)
if err != nil {
klog.ErrorS(err, "Failed to retrieve CRP generation from annoation", "clusterSchedulingPolicySnapshot", policyRef)
return controller.NewUnexpectedBehaviorError(err)
}

// Update the status.
policy.Status.ClusterDecisions = newDecisions
policy.Status.ObservedCRPGeneration = observedCRPGeneration
Expand Down Expand Up @@ -1276,6 +1281,13 @@ func (f *framework) updatePolicySnapshotStatusForPickFixedPlacementType(
) error {
policyRef := klog.KObj(policy)

// Retrieve the corresponding CRP generation.
observedCRPGeneration, err := annotations.ExtractObservedCRPGenerationFromPolicySnapshot(policy)
if err != nil {
klog.ErrorS(err, "Failed to retrieve CRP generation from annotation", "clusterSchedulingPolicySnapshot", policyRef)
return controller.NewUnexpectedBehaviorError(err)
}

// Prepare new scheduling decisions.
newDecisions := newSchedulingDecisionsForPickFixedPlacementType(valid, invalid, notFound)
// Prepare new scheduling condition.
Expand All @@ -1291,18 +1303,16 @@ func (f *framework) updatePolicySnapshotStatusForPickFixedPlacementType(
// Compare new decisions + condition with the old ones.
currentDecisions := policy.Status.ClusterDecisions
currentCondition := meta.FindStatusCondition(policy.Status.Conditions, string(placementv1beta1.PolicySnapshotScheduled))
if equalDecisions(currentDecisions, newDecisions) && condition.EqualCondition(currentCondition, &newCondition) {
if observedCRPGeneration == policy.Status.ObservedCRPGeneration &&
equalDecisions(currentDecisions, newDecisions) &&
condition.EqualCondition(currentCondition, &newCondition) {
// Skip if there is no change in decisions and conditions.
klog.InfoS(
"No change in scheduling decisions and condition, and the observed CRP generation remains the same",
"clusterSchedulingPolicySnapshot", policyRef)
return nil
}

// Retrieve the corresponding CRP generation.
observedCRPGeneration, err := annotations.ExtractObservedCRPGenerationFromPolicySnapshot(policy)
if err != nil {
klog.ErrorS(err, "Failed to retrieve CRP generation from annotation", "clusterSchedulingPolicySnapshot", policyRef)
return controller.NewUnexpectedBehaviorError(err)
}

// Update the status.
policy.Status.ClusterDecisions = newDecisions
policy.Status.ObservedCRPGeneration = observedCRPGeneration
Expand Down
Loading