volcano.sh/volcano@v1.9.0/pkg/scheduler/plugins/predicates/proportional.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 predicates
    18  
    19  import (
    20  	"fmt"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  
    24  	"volcano.sh/volcano/pkg/scheduler/api"
    25  )
    26  
    27  // checkNodeResourceIsProportional checks if a gpu:cpu:memory is Proportional
    28  func checkNodeResourceIsProportional(task *api.TaskInfo, node *api.NodeInfo, proportional map[v1.ResourceName]baseResource) (*api.Status, error) {
    29  	status := &api.Status{
    30  		Code: api.Success,
    31  	}
    32  	for resourceName := range proportional {
    33  		if value, found := task.Resreq.ScalarResources[resourceName]; found && value > 0 {
    34  			return status, nil
    35  		}
    36  	}
    37  
    38  	for resourceName, resourceRate := range proportional {
    39  		if value, found := node.Idle.ScalarResources[resourceName]; found {
    40  			cpuReserved := value * resourceRate.CPU
    41  			memoryReserved := value * resourceRate.Memory * 1000 * 1000
    42  
    43  			if node.Idle.MilliCPU-task.Resreq.MilliCPU < cpuReserved || node.Idle.Memory-task.Resreq.Memory < memoryReserved {
    44  				status.Code = api.UnschedulableAndUnresolvable
    45  				status.Reason = fmt.Sprintf("proportional of resource %s check failed", resourceName)
    46  				return status, fmt.Errorf("proportional of resource %s check failed", resourceName)
    47  			}
    48  		}
    49  	}
    50  	return status, nil
    51  }