func fitsResourceQuota()

in pkg/scheduler/flavorassigner/flavorassigner.go [442:484]


func fitsResourceQuota(fName kueue.ResourceFlavorReference, rName corev1.ResourceName, val int64, cq *cache.ClusterQueue, rQuota *cache.ResourceQuota) (FlavorAssignmentMode, int64, *Status) {
	var status Status
	used := cq.Usage[fName][rName]
	mode := NoFit
	if val <= rQuota.Nominal {
		// The request can be satisfied by the min quota, assuming quota is
		// reclaimed from the cohort or assuming all active workloads in the
		// ClusterQueue are preempted.
		mode = Preempt
	}
	if rQuota.BorrowingLimit != nil && used+val > rQuota.Nominal+*rQuota.BorrowingLimit {
		status.append(fmt.Sprintf("borrowing limit for %s in flavor %s exceeded", rName, fName))
		return mode, 0, &status
	}

	cohortUsed := used
	cohortAvailable := rQuota.Nominal
	if cq.Cohort != nil {
		cohortUsed = cq.Cohort.Usage[fName][rName]
		cohortAvailable = cq.Cohort.RequestableResources[fName][rName]
	}

	lack := cohortUsed + val - cohortAvailable
	if lack <= 0 {
		borrow := used + val - rQuota.Nominal
		if borrow < 0 {
			borrow = 0
		}
		return Fit, borrow, nil
	}

	lackQuantity := workload.ResourceQuantity(rName, lack)
	msg := fmt.Sprintf("insufficient unused quota in cohort for %s in flavor %s, %s more needed", rName, fName, &lackQuantity)
	if cq.Cohort == nil {
		if mode == NoFit {
			msg = fmt.Sprintf("insufficient quota for %s in flavor %s in ClusterQueue", rName, fName)
		} else {
			msg = fmt.Sprintf("insufficient unused quota for %s in flavor %s, %s more needed", rName, fName, &lackQuantity)
		}
	}
	status.append(msg)
	return mode, 0, &status
}