From 712d6ef8db9da5df4e7518d7aaa4d7b80352695b Mon Sep 17 00:00:00 2001 From: John Wregglesworth Date: Thu, 17 Nov 2022 14:59:22 -0700 Subject: [PATCH] Compare usage to quota to determine overage status --- internal/limits.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/limits.go b/internal/limits.go index 89d9de5..4798458 100644 --- a/internal/limits.go +++ b/internal/limits.go @@ -193,20 +193,28 @@ func validateJobLimits(user string, defaultJobLimit, jobCount int, jobLimit *int return http.StatusBadRequest, buildLimitError(code, msg, defaultJobLimit, jobCount, jobLimit) case overages != nil && len(overages.Overages) != 0: + var inOverage bool code := "ERR_RESOURCE_OVERAGE" - msg := fmt.Sprintf("%s has resource overages.", user) details := make(map[string]interface{}) for _, ov := range overages.Overages { - details[ov.ResourceName] = fmt.Sprintf("quota: %f, usage: %f", ov.Quota, ov.Usage) + if ov.Usage >= ov.Quota { + inOverage = true + details[ov.ResourceName] = fmt.Sprintf("quota: %f, usage: %f", ov.Quota, ov.Usage) + } } - return http.StatusBadRequest, common.ErrorResponse{ - ErrorCode: code, - Message: msg, - Details: &details, + if inOverage { + msg := fmt.Sprintf("%s has resource overages.", user) + return http.StatusBadRequest, common.ErrorResponse{ + ErrorCode: code, + Message: msg, + Details: &details, + } } + return http.StatusOK, nil + // In every other case, we can permit the job to be launched. default: return http.StatusOK, nil