Skip to content

Commit 00e5d02

Browse files
committed
address review-2
1 parent 3ac5a83 commit 00e5d02

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package quota
1919
import (
2020
"bytes"
2121
"fmt"
22-
"regexp"
2322
"strings"
2423

2524
clientset "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset/controller-versioned"
2625
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/quotaplugins/quota-forest/quota-manager/quota/core"
2726
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/quotaplugins/quota-forest/quota-manager/quota/utils"
27+
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/quotaplugins/util"
2828
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/client-go/rest"
3030
"k8s.io/klog/v2"
@@ -369,29 +369,31 @@ 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
373372
if forestController == nil {
374373
return nil, fmt.Errorf("invalid forest name %s", forestName)
375374
}
376375
consumerInfo := m.consumerInfos[consumerID]
377376
if consumerInfo == nil {
378377
return nil, fmt.Errorf("consumer %s does not exist, create and add first", consumerID)
379378
}
380-
//allocation can pass if consumers are not released
379+
//allocation can pass if consumers inside the forest is not released
381380
//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]
381+
namespace, awName := util.ParseId(consumerID)
386382
config, err := rest.InClusterConfig()
387383
if err != nil {
388384
klog.Errorf("unable to retrieve in-cluster kubeconfig %v", err)
389385
}
390386
arbclients := clientset.NewForConfigOrDie(config)
391387
awQueried, err := arbclients.ArbV1().AppWrappers(namespace).Get(awName, v1.GetOptions{})
388+
var awExistsInNamespace bool = false
389+
if err != nil {
390+
klog.Errorf("Unable to query consumer %v,", consumerID)
391+
//force set to true
392+
awExistsInNamespace = true
393+
}
392394
if awQueried.Name == awName {
393395
awExistsInNamespace = true
394-
klog.V(5).Infof("Found consumer %v in namespace", consumerID)
396+
klog.V(5).Infof("[AllocateForest] Found consumer %v in namespace", consumerID)
395397
}
396398
if awExistsInNamespace {
397399
if forestController.IsConsumerAllocated(consumerID) {

0 commit comments

Comments
 (0)