Skip to content

refactor: update PolicyObservedClusterCount in one place in collectScheduledClusters#692

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/refactor-policyobservedclustercount-update
Draft

refactor: update PolicyObservedClusterCount in one place in collectScheduledClusters#692
Copilot wants to merge 3 commits into
mainfrom
copilot/refactor-policyobservedclustercount-update

Conversation

Copilot AI commented May 5, 2026

Copy link
Copy Markdown
Contributor

PolicyObservedClusterCount was written in two places: determinePolicySnapshot set it to -1 as a sentinel for PickAll policy, then collectScheduledClusters detected that sentinel and overwrote it with len(selectedBindings).

Changes

  • determinePolicySnapshot: Remove the PolicyObservedClusterCount assignment entirely; update the klog to reference the local clusterCount variable directly.
  • collectScheduledClusters: Add clusterCount int parameter. Validate count mismatch first, then set PolicyObservedClusterCount = len(selectedBindings) unconditionally in one place — valid for both PickAll (clusterCount == -1) and other policies (where the preceding check guarantees clusterCount == len(selectedBindings)).
  • Callers: initialize now captures and forwards clusterCount; validate forwards its existing clusterCount.
// Before: two assignments, sentinel-based indirection
updateRunStatus.PolicyObservedClusterCount = clusterCount // -1 for PickAll, set in determinePolicySnapshot
...
if updateRunStatus.PolicyObservedClusterCount == -1 {     // overwritten in collectScheduledClusters
    updateRunStatus.PolicyObservedClusterCount = len(selectedBindings)
} else if updateRunStatus.PolicyObservedClusterCount != len(selectedBindings) { ... }

// After: single assignment in collectScheduledClusters
if clusterCount != -1 && clusterCount != len(selectedBindings) {
    return nil, nil, fmt.Errorf(...)  // mismatch error
}
updateRunStatus.PolicyObservedClusterCount = len(selectedBindings)  // always set here

Copilot AI and others added 2 commits May 5, 2026 18:03
…heduledClusters

Agent-Logs-Url: https://github.com/kubefleet-dev/kubefleet/sessions/8cb9e894-f2d2-498f-970a-4242477b9f20

Co-authored-by: britaniar <145056127+britaniar@users.noreply.github.com>
… in collectScheduledClusters

Agent-Logs-Url: https://github.com/kubefleet-dev/kubefleet/sessions/8cb9e894-f2d2-498f-970a-4242477b9f20

Co-authored-by: britaniar <145056127+britaniar@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to update PolicyObservedClusterCount in one place refactor: update PolicyObservedClusterCount in one place in collectScheduledClusters May 5, 2026
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.

Staged Update Run: Refactor to update PolicyObservedClusterCount in one place

2 participants