sigs.k8s.io/kueue@v0.6.2/pkg/queue/local_queue.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package queue
    18  
    19  import (
    20  	"fmt"
    21  
    22  	kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
    23  	"sigs.k8s.io/kueue/pkg/workload"
    24  )
    25  
    26  func keyFunc(obj interface{}) string {
    27  	i := obj.(*workload.Info)
    28  	return workload.Key(i.Obj)
    29  }
    30  
    31  // Key is the key used to index the queue.
    32  func Key(q *kueue.LocalQueue) string {
    33  	return fmt.Sprintf("%s/%s", q.Namespace, q.Name)
    34  }
    35  
    36  // LocalQueue is the internal implementation of kueue.LocalQueue.
    37  type LocalQueue struct {
    38  	Key          string
    39  	ClusterQueue string
    40  
    41  	items map[string]*workload.Info
    42  }
    43  
    44  func newLocalQueue(q *kueue.LocalQueue) *LocalQueue {
    45  	qImpl := &LocalQueue{
    46  		Key:   Key(q),
    47  		items: make(map[string]*workload.Info),
    48  	}
    49  	qImpl.update(q)
    50  	return qImpl
    51  }
    52  
    53  func (q *LocalQueue) update(apiQueue *kueue.LocalQueue) {
    54  	q.ClusterQueue = string(apiQueue.Spec.ClusterQueue)
    55  }
    56  
    57  func (q *LocalQueue) AddOrUpdate(info *workload.Info) {
    58  	key := workload.Key(info.Obj)
    59  	q.items[key] = info
    60  }