Skip to content

Commit 19d60d2

Browse files
atantawiopenshift-merge-robot
authored andcommitted
handle invalid tree in forest consumer
1 parent 832f264 commit 19d60d2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pkg/quotaplugins/quota-forest/quota-manager/quota/core/forestcontroller.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Multi-Cluster App Dispatcher Authors.
2+
Copyright 2022, 2023 The Multi-Cluster App Dispatcher Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -135,6 +135,15 @@ func (fc *ForestController) Allocate(forestConsumer *ForestConsumer) *Allocation
135135
for treeName, consumer := range consumers {
136136

137137
controller := fc.controllers[treeName]
138+
if controller == nil {
139+
// skip, unknown tree
140+
treeAllocResponse := NewAllocationResponse(consumerID)
141+
var msg bytes.Buffer
142+
fmt.Fprintf(&msg, "Failed to allocate consumer %s on unknown tree %s'", consumerID, treeName)
143+
treeAllocResponse.Append(false, msg.String(), nil)
144+
allocResponse.Merge(treeAllocResponse)
145+
continue
146+
}
138147
groupID := consumer.GetGroupID()
139148
allocRequested := consumer.GetRequest()
140149
if controller == nil || len(groupID) == 0 || allocRequested.GetSize() != controller.GetQuotaSize() {
@@ -256,6 +265,10 @@ func (fc *ForestController) TryAllocate(forestConsumer *ForestConsumer) *Allocat
256265
for treeName, consumer := range consumers {
257266
var msg bytes.Buffer
258267
controller := fc.controllers[treeName]
268+
if controller == nil {
269+
// skip, unknown tree
270+
continue
271+
}
259272
controller.treeSnapshot = NewTreeSnapshot(controller.tree, consumer)
260273
// TODO: limit the number of potentially affected consumers by the allocation
261274
if !controller.treeSnapshot.Take(controller, controller.consumers) {
@@ -280,6 +293,10 @@ func (fc *ForestController) UndoAllocate(forestConsumer *ForestConsumer) bool {
280293
success := true
281294
for treeName, consumer := range consumers {
282295
controller := fc.controllers[treeName]
296+
if controller == nil {
297+
// skip, unknown tree
298+
continue
299+
}
283300
treeSuccess := controller.UndoAllocate(consumer)
284301
success = success && treeSuccess
285302
}

0 commit comments

Comments
 (0)