@@ -369,33 +369,40 @@ func (m *Manager) UpdateForest(forestName string) (unallocatedConsumerIDs []stri
369
369
// AllocateForest : allocate a consumer on a forest
370
370
func (m * Manager ) AllocateForest (forestName string , consumerID string ) (response * core.AllocationResponse , err error ) {
371
371
forestController := m .forests [forestName ]
372
+ var awExistsInNamespace bool = false
372
373
if forestController == nil {
373
374
return nil , fmt .Errorf ("invalid forest name %s" , forestName )
374
375
}
375
376
consumerInfo := m .consumerInfos [consumerID ]
376
377
if consumerInfo == nil {
377
378
return nil , fmt .Errorf ("consumer %s does not exist, create and add first" , consumerID )
378
379
}
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 ) {
393
398
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 ) {
396
402
m .DeAllocateForest (forestName , consumerID )
397
403
}
398
404
}
405
+
399
406
resourceNames := forestController .GetResourceNames ()
400
407
forestConsumer , err := consumerInfo .CreateForestConsumer (forestName , resourceNames )
401
408
if err != nil {
0 commit comments