feat: add InterpretSchedulingResult operation to ResourceInterpreter #6977
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the feature requested in GitHub issue #3459 to enable interpreting customized scheduling results in the ResourceInterpreter.
The issue describes two critical scenarios that need to be addressed:
Remainder Distribution Problem: When distributing replicas across clusters with equal weights, remainders from uneven division always go to the same cluster. For workloads with
replicas = 1or when replica counts can't be evenly divided by cluster weights, Karmada currently schedules remainders to the same cluster consistently, leading to imbalanced resource utilization.Member Cluster Synchronization: When HPA controllers work independently in member clusters, replica changes need to be synchronized back to the control plane to maintain a consistent global perspective and prevent workload disruption during cluster transitions.
This PR adds a new
InterpretSchedulingResultoperation to the ResourceInterpreter framework that allows customizing how replicas are distributed among clusters through:Which issue(s) this PR fixes
Fixes #3459
Special notes for your reviewer
This implementation provides a flexible framework for custom scheduling algorithms while maintaining full backward compatibility. The feature is opt-in and only activates when explicitly configured.
Key architectural decisions:
InterpreterOperationInterpretSchedulingResultoperation typeResourceInterpreterinterface withInterpretSchedulingResult()methodDoes this PR introduce a user-facing change?
Detailed Implementation
API Extensions
InterpreterOperationInterpretSchedulingResultoperation type toconfigv1alpha1ResourceInterpreterinterface withInterpretSchedulingResult(object, schedulingResult) ([]TargetCluster, error)methodSchedulingResultInterpretationtype for declarative configurationsInterpreter Implementations
Lua VM Integration
InterpretSchedulingResult()method to Lua VM for script executionConvertLuaResultToTargetClusters()for Lua-to-Go conversion