Skip to content

Commit ce7d9bc

Browse files
Add toggle for nova input host safety measure (#616)
With this change we can now toggle the `limitHostsToRequest` functionality inside the external scheduler api for nova. This is needed because we will completely ignore nova's input soon, and nova will handle keyerrors for unknown proposed hosts appropriately. Thus, before we will completely remove this safety measure from the code, we add this toggle to turn it off.
1 parent 5153b5a commit ce7d9bc

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ func main() {
322322
setupLog.Error(err, "unable to create controller", "controller", "nova FilterWeigherPipelineController")
323323
os.Exit(1)
324324
}
325-
nova.NewAPI(filterWeigherController).Init(mux)
325+
novaAPIConfig := conf.GetConfigOrDie[nova.HTTPAPIConfig]()
326+
nova.NewAPI(novaAPIConfig, filterWeigherController).Init(mux)
326327

327328
// Initialize commitments API for LIQUID interface
328329
commitmentsAPI := commitments.NewAPI(multiclusterClient)

helm/bundles/cortex-nova/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ cortex-scheduling-controllers:
138138
- failover-reservations-controller
139139
enabledTasks:
140140
- nova-history-cleanup-task
141+
# If true, the external scheduler API will limit the list of hosts in its
142+
# response to those included in the scheduling request.
143+
novaLimitHostsToRequest: true
141144
# CommittedResourceFlavorGroupPipelines maps flavor group IDs to pipeline names for CR reservations
142145
# This allows different scheduling strategies per flavor group (e.g., HANA vs GP)
143146
committedResourceFlavorGroupPipelines:

internal/scheduling/nova/external_scheduler_api.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,23 @@ type HTTPAPI interface {
3434
Init(*http.ServeMux)
3535
}
3636

37+
type HTTPAPIConfig struct {
38+
// NovaLimitHostsToRequest, if true, will filter the Nova scheduler response
39+
// to only include hosts that were in the original request.
40+
NovaLimitHostsToRequest bool `json:"novaLimitHostsToRequest,omitempty"`
41+
}
42+
3743
type httpAPI struct {
3844
monitor scheduling.APIMonitor
3945
delegate HTTPAPIDelegate
46+
config HTTPAPIConfig
4047
}
4148

42-
func NewAPI(delegate HTTPAPIDelegate) HTTPAPI {
49+
func NewAPI(config HTTPAPIConfig, delegate HTTPAPIDelegate) HTTPAPI {
4350
return &httpAPI{
4451
monitor: scheduling.NewSchedulerMonitor(),
4552
delegate: delegate,
53+
config: config,
4654
}
4755
}
4856

@@ -222,7 +230,11 @@ func (httpAPI *httpAPI) NovaExternalScheduler(w http.ResponseWriter, r *http.Req
222230
return
223231
}
224232
hosts := decision.Status.Result.OrderedHosts
225-
hosts = limitHostsToRequest(requestData, hosts)
233+
if httpAPI.config.NovaLimitHostsToRequest {
234+
hosts = limitHostsToRequest(requestData, hosts)
235+
slog.Info("limited hosts to request",
236+
"hosts", hosts, "originalHosts", decision.Status.Result.OrderedHosts)
237+
}
226238
response := api.ExternalSchedulerResponse{Hosts: hosts}
227239
w.Header().Set("Content-Type", "application/json")
228240
if err = json.NewEncoder(w).Encode(response); err != nil {

internal/scheduling/nova/external_scheduler_api_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (m *mockHTTPAPIDelegate) ProcessNewDecisionFromAPI(ctx context.Context, dec
3333
func TestNewAPI(t *testing.T) {
3434
delegate := &mockHTTPAPIDelegate{}
3535

36-
api := NewAPI(delegate)
36+
api := NewAPI(HTTPAPIConfig{}, delegate)
3737

3838
if api == nil {
3939
t.Fatal("NewAPI returned nil")
@@ -55,7 +55,7 @@ func TestNewAPI(t *testing.T) {
5555

5656
func TestHTTPAPI_Init(t *testing.T) {
5757
delegate := &mockHTTPAPIDelegate{}
58-
api := NewAPI(delegate)
58+
api := NewAPI(HTTPAPIConfig{}, delegate)
5959

6060
mux := http.NewServeMux()
6161
api.Init(mux)
@@ -73,7 +73,7 @@ func TestHTTPAPI_Init(t *testing.T) {
7373

7474
func TestHTTPAPI_canRunScheduler(t *testing.T) {
7575
delegate := &mockHTTPAPIDelegate{}
76-
api := NewAPI(delegate).(*httpAPI)
76+
api := NewAPI(HTTPAPIConfig{}, delegate).(*httpAPI)
7777

7878
tests := []struct {
7979
name string
@@ -276,7 +276,7 @@ func TestHTTPAPI_NovaExternalScheduler(t *testing.T) {
276276
},
277277
}
278278

279-
api := NewAPI(delegate).(*httpAPI)
279+
api := NewAPI(HTTPAPIConfig{}, delegate).(*httpAPI)
280280

281281
var body *strings.Reader
282282
if tt.body != "" {
@@ -327,7 +327,7 @@ func TestHTTPAPI_NovaExternalScheduler_DecisionCreation(t *testing.T) {
327327
},
328328
}
329329

330-
api := NewAPI(delegate).(*httpAPI)
330+
api := NewAPI(HTTPAPIConfig{}, delegate).(*httpAPI)
331331

332332
requestData := novaapi.ExternalSchedulerRequest{
333333
Spec: novaapi.NovaObject[novaapi.NovaSpec]{
@@ -508,7 +508,7 @@ func TestLimitHostsToRequest(t *testing.T) {
508508

509509
func TestHTTPAPI_inferPipelineName(t *testing.T) {
510510
delegate := &mockHTTPAPIDelegate{}
511-
api := NewAPI(delegate).(*httpAPI)
511+
api := NewAPI(HTTPAPIConfig{}, delegate).(*httpAPI)
512512

513513
tests := []struct {
514514
name string

0 commit comments

Comments
 (0)