Skip to content

Commit a84b356

Browse files
committed
resolve review
1 parent d2ade32 commit a84b356

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

pkg/quotaplugins/quota-forest/quota-manager/quota/quotamanager.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,33 +369,40 @@ func (m *Manager) UpdateForest(forestName string) (unallocatedConsumerIDs []stri
369369
// AllocateForest : allocate a consumer on a forest
370370
func (m *Manager) AllocateForest(forestName string, consumerID string) (response *core.AllocationResponse, err error) {
371371
forestController := m.forests[forestName]
372+
var awExistsInNamespace bool = false
372373
if forestController == nil {
373374
return nil, fmt.Errorf("invalid forest name %s", forestName)
374375
}
375376
consumerInfo := m.consumerInfos[consumerID]
376377
if consumerInfo == nil {
377378
return nil, fmt.Errorf("consumer %s does not exist, create and add first", consumerID)
378379
}
379-
if forestController.IsConsumerAllocated(consumerID) {
380-
//allocation can pass if consumers are not released
381-
//make sure that appwrapper (consumer) does not exist in target namespace
382-
re := regexp.MustCompile("_")
383-
split := re.Split(consumerID, -1)
384-
namespace := split[1]
385-
awName := split[3]
386-
config, err := rest.InClusterConfig()
387-
if err != nil {
388-
klog.Errorf("unable to retrieve in-cluster kubeconfig %v", err)
389-
}
390-
arbclients := clientset.NewForConfigOrDie(config)
391-
_, err = arbclients.ArbV1().AppWrappers(namespace).Get(awName, v1.GetOptions{})
392-
if err != nil {
380+
//allocation can pass if consumers are not released
381+
//make sure that appwrapper (consumer) does not exist in target namespace
382+
re := regexp.MustCompile("_")
383+
split := re.Split(consumerID, -1)
384+
namespace := split[1]
385+
awName := split[3]
386+
config, err := rest.InClusterConfig()
387+
if err != nil {
388+
klog.Errorf("unable to retrieve in-cluster kubeconfig %v", err)
389+
}
390+
arbclients := clientset.NewForConfigOrDie(config)
391+
awQueried, err := arbclients.ArbV1().AppWrappers(namespace).Get(awName, v1.GetOptions{})
392+
if awQueried.Name == awName {
393+
awExistsInNamespace = true
394+
klog.V(5).Infof("Found consumer %v in namespace", consumerID)
395+
}
396+
if awExistsInNamespace {
397+
if forestController.IsConsumerAllocated(consumerID) {
393398
return nil, fmt.Errorf("consumer %s already allocated on forest %s", consumerID, forestName)
394-
} else {
395-
//release quota
399+
}
400+
} else {
401+
if forestController.IsConsumerAllocated(consumerID) {
396402
m.DeAllocateForest(forestName, consumerID)
397403
}
398404
}
405+
399406
resourceNames := forestController.GetResourceNames()
400407
forestConsumer, err := consumerInfo.CreateForestConsumer(forestName, resourceNames)
401408
if err != nil {

0 commit comments

Comments
 (0)