volcano.sh/volcano@v1.9.0/pkg/scheduler/api/queue_info.go (about)

     1  /*
     2  Copyright 2018 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 api
    18  
    19  import (
    20  	"k8s.io/apimachinery/pkg/types"
    21  
    22  	"volcano.sh/apis/pkg/apis/scheduling"
    23  	"volcano.sh/apis/pkg/apis/scheduling/v1beta1"
    24  )
    25  
    26  // QueueID is UID type, serves as unique ID for each queue
    27  type QueueID types.UID
    28  
    29  // QueueInfo will have all details about queue
    30  type QueueInfo struct {
    31  	UID  QueueID
    32  	Name string
    33  
    34  	Weight int32
    35  
    36  	// Weights is a list of slash sperated float numbers.
    37  	// Each of them is a weight corresponding the
    38  	// hierarchy level.
    39  	Weights string
    40  	// Hierarchy is a list of node name along the
    41  	// path from the root to the node itself.
    42  	Hierarchy string
    43  
    44  	Queue *scheduling.Queue
    45  }
    46  
    47  // NewQueueInfo creates new queueInfo object
    48  func NewQueueInfo(queue *scheduling.Queue) *QueueInfo {
    49  	return &QueueInfo{
    50  		UID:  QueueID(queue.Name),
    51  		Name: queue.Name,
    52  
    53  		Weight:    queue.Spec.Weight,
    54  		Hierarchy: queue.Annotations[v1beta1.KubeHierarchyAnnotationKey],
    55  		Weights:   queue.Annotations[v1beta1.KubeHierarchyWeightAnnotationKey],
    56  
    57  		Queue: queue,
    58  	}
    59  }
    60  
    61  // Clone is used to clone queueInfo object
    62  func (q *QueueInfo) Clone() *QueueInfo {
    63  	return &QueueInfo{
    64  		UID:       q.UID,
    65  		Name:      q.Name,
    66  		Weight:    q.Weight,
    67  		Hierarchy: q.Hierarchy,
    68  		Weights:   q.Weights,
    69  		Queue:     q.Queue,
    70  	}
    71  }
    72  
    73  // Reclaimable return whether queue is reclaimable
    74  func (q *QueueInfo) Reclaimable() bool {
    75  	if q == nil {
    76  		return false
    77  	}
    78  
    79  	if q.Queue == nil {
    80  		return false
    81  	}
    82  
    83  	if q.Queue.Spec.Reclaimable == nil {
    84  		return true
    85  	}
    86  
    87  	return *q.Queue.Spec.Reclaimable
    88  }