-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add basic support for flavor groups for failover reservation #754
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9759b03
fix: add FindFlavorInGroups
umswmayj e72c982
fix: Add option to create failover reservation in the size of the lar…
umswmayj 93f1a47
Add IsReady for reservations
umswmayj 29efb2f
feat: add kmv failover consolidation weigher
umswmayj 04d2646
fix: address PR review feedback for flavor group support
umswmayj ade2e07
Merge branch 'main' into ha_flavor_groups
umswmayj 6a919ff
pr comment
umswmayj 0fbe302
enable useFlavorGroupResources
umswmayj 7405b73
set useFlavorGroupResources to false
umswmayj 8d14965
Merge remote-tracking branch 'origin/main' into ha_flavor_groups
umswmayj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
internal/scheduling/nova/plugins/weighers/kvm_failover_reservation_consolidation.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // Copyright SAP SE | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package weighers | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "log/slog" | ||
|
|
||
| api "github.com/cobaltcore-dev/cortex/api/external/nova" | ||
| "github.com/cobaltcore-dev/cortex/api/v1alpha1" | ||
| "github.com/cobaltcore-dev/cortex/internal/scheduling/lib" | ||
| ) | ||
|
|
||
| // Options for the KVM failover reservation consolidation weigher. | ||
| type KVMFailoverReservationConsolidationOpts struct { | ||
| // Weight multiplier for the total failover reservation count per host (consolidation signal). | ||
| // Higher values more aggressively pack failover reservations onto fewer hosts. | ||
| // Default: 1.0 | ||
| TotalCountWeight *float64 `json:"totalCountWeight,omitempty"` | ||
| // Penalty multiplier for same-spec reservation count per host (diversity signal). | ||
| // Higher values more aggressively avoid clustering reservations of the same size on one host. | ||
| // Should be less than TotalCountWeight to ensure consolidation is the primary goal. | ||
| // Default: 0.1 | ||
| SameSpecPenalty *float64 `json:"sameSpecPenalty,omitempty"` | ||
| } | ||
|
|
||
| func (o KVMFailoverReservationConsolidationOpts) Validate() error { | ||
| w := o.GetTotalCountWeight() | ||
| p := o.GetSameSpecPenalty() | ||
| if w < 0 { | ||
| return errors.New("totalCountWeight must be non-negative") | ||
| } | ||
| if p < 0 { | ||
| return errors.New("sameSpecPenalty must be non-negative") | ||
| } | ||
| if w == 0 && p > 0 { | ||
| return errors.New("sameSpecPenalty must be zero when totalCountWeight is zero") | ||
| } | ||
| if w > 0 && p >= w { | ||
| return errors.New("sameSpecPenalty must be less than totalCountWeight") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (o KVMFailoverReservationConsolidationOpts) GetTotalCountWeight() float64 { | ||
| if o.TotalCountWeight == nil { | ||
| return 1.0 | ||
| } | ||
| return *o.TotalCountWeight | ||
| } | ||
|
|
||
| func (o KVMFailoverReservationConsolidationOpts) GetSameSpecPenalty() float64 { | ||
| if o.SameSpecPenalty == nil { | ||
| return 0.1 | ||
| } | ||
| return *o.SameSpecPenalty | ||
| } | ||
|
|
||
| // KVMFailoverReservationConsolidationStep weighs hosts for failover reservation placement. | ||
| // It encourages consolidating failover reservations onto as few hosts as possible (primary goal), | ||
| // while preferring hosts with fewer reservations of the same ResourceGroup (secondary tiebreaker). | ||
| // | ||
| // The ResourceGroup is passed via the scheduler hint "_cortex_resource_group" and compared against | ||
| // each existing reservation's Spec.FailoverReservation.ResourceGroup. This groups reservations | ||
| // by flavor group (or individual flavor name when no group exists). | ||
| // | ||
| // Score formula (normalized by total reservation count T): | ||
| // | ||
| // score = (totalCountWeight / T) × hostCount - (sameSpecPenalty / T) × sameGroupCount | ||
| // | ||
| // This produces bounded output (~0 to 1) that plays nicely with other weighers. | ||
| type KVMFailoverReservationConsolidationStep struct { | ||
| lib.BaseWeigher[api.ExternalSchedulerRequest, KVMFailoverReservationConsolidationOpts] | ||
| } | ||
|
|
||
| // Run the weigher step. | ||
| // For reserve_for_failover requests, hosts are scored based on existing failover reservation density | ||
| // and same-spec diversity. For all other request types, this weigher has no effect. | ||
| func (s *KVMFailoverReservationConsolidationStep) Run(traceLog *slog.Logger, request api.ExternalSchedulerRequest) (*lib.FilterWeigherPipelineStepResult, error) { | ||
| result := s.IncludeAllHostsFromRequest(request) | ||
|
|
||
| intent, err := request.GetIntent() | ||
| if err != nil || intent != api.ReserveForFailoverIntent { | ||
| traceLog.Info("skipping failover reservation consolidation weigher for non-failover-reservation request") | ||
| return result, nil //nolint:nilerr // intentionally skip weigher on error | ||
| } | ||
|
umswmayj marked this conversation as resolved.
|
||
|
|
||
| // Extract the resource group from the scheduler hint. | ||
| // This identifies which "spec group" the incoming reservation belongs to. | ||
| // If the hint is missing, requestResourceGroup will be empty and the same-group penalty is skipped. | ||
| requestResourceGroup, _ := request.Spec.Data.GetSchedulerHintStr(api.HintKeyResourceGroup) //nolint:errcheck // missing hint is fine, same-group penalty is simply skipped | ||
|
|
||
| // Fetch all reservations. | ||
| var reservations v1alpha1.ReservationList | ||
| if err := s.Client.List(context.Background(), &reservations); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Count failover reservations per host, and same-group reservations per host. | ||
| totalPerHost := make(map[string]float64) | ||
| sameGroupPerHost := make(map[string]float64) | ||
| totalReservations := 0 | ||
|
|
||
| for _, reservation := range reservations.Items { | ||
| // Only consider active failover reservations (Ready condition is True). | ||
| if !reservation.IsReady() { | ||
| continue | ||
| } | ||
| if reservation.Spec.Type != v1alpha1.ReservationTypeFailover { | ||
| continue | ||
| } | ||
|
|
||
| host := reservation.Status.Host | ||
| if host == "" { | ||
| continue | ||
| } | ||
|
|
||
| totalReservations++ | ||
| totalPerHost[host]++ | ||
|
|
||
| // Check if this reservation belongs to the same resource group as the request. | ||
| if requestResourceGroup != "" && reservation.Spec.FailoverReservation != nil && | ||
| reservation.Spec.FailoverReservation.ResourceGroup == requestResourceGroup { | ||
| sameGroupPerHost[host]++ | ||
| } | ||
| } | ||
|
|
||
| // If there are no failover reservations, the weigher has no information to act on. | ||
| if totalReservations == 0 { | ||
| traceLog.Info("no active failover reservations found, skipping consolidation weigher") | ||
| return result, nil | ||
| } | ||
|
|
||
| totalCountWeight := s.Options.GetTotalCountWeight() | ||
| sameSpecPenalty := s.Options.GetSameSpecPenalty() | ||
| t := float64(totalReservations) | ||
|
|
||
| for _, host := range request.Hosts { | ||
| hostTotal := totalPerHost[host.ComputeHost] | ||
| hostSameGroup := sameGroupPerHost[host.ComputeHost] | ||
|
|
||
| // Normalized score: bounded output for compatibility with other weighers. | ||
| score := (totalCountWeight/t)*hostTotal - (sameSpecPenalty/t)*hostSameGroup | ||
|
|
||
| result.Activations[host.ComputeHost] = score | ||
| traceLog.Info("calculated failover consolidation score for host", | ||
| "host", host.ComputeHost, | ||
| "totalOnHost", hostTotal, | ||
| "sameGroupOnHost", hostSameGroup, | ||
| "resourceGroup", requestResourceGroup, | ||
| "totalReservations", totalReservations, | ||
| "score", score) | ||
| } | ||
|
|
||
| return result, nil | ||
| } | ||
|
|
||
| func init() { | ||
| Index["kvm_failover_reservation_consolidation"] = func() NovaWeigher { | ||
| return &KVMFailoverReservationConsolidationStep{} | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.