-
Notifications
You must be signed in to change notification settings - Fork 607
fix(quota): enforce explicit zero limit in ResourceQuota #1904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,8 +25,9 @@ import ( | |||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| type Quota struct { | ||||||||||||||||||||||||||||||||||||
| Used int64 | ||||||||||||||||||||||||||||||||||||
| Limit int64 | ||||||||||||||||||||||||||||||||||||
| Used int64 | ||||||||||||||||||||||||||||||||||||
| Limit int64 | ||||||||||||||||||||||||||||||||||||
| LimitSet bool | ||||||||||||||||||||||||||||||||||||
|
iasthc marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can set the default value of limit to MaxInt64 to avoid introducing a new variable. The information from ResourceQuota will be used in metrics as below. Lines 299 to 315 in f852784
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I think
The metrics commit is on top of the quota fixes, rebased onto current master — PTAL. |
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| type DeviceQuota map[string]*Quota | ||||||||||||||||||||||||||||||||||||
|
|
@@ -69,19 +70,19 @@ func (q *QuotaManager) FitQuota(ns string, memreq int64, memoryFactor int32, cor | |||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| memQuota, ok := (*dq)[memResourceName] | ||||||||||||||||||||||||||||||||||||
| if ok { | ||||||||||||||||||||||||||||||||||||
| if ok && memQuota.LimitSet { | ||||||||||||||||||||||||||||||||||||
| klog.V(4).InfoS("resourceMem quota judging", "quota limit", memQuota.Limit, "used", memQuota.Used, "alloc", memreq, "memoryFactor", memoryFactor) | ||||||||||||||||||||||||||||||||||||
| limit := memQuota.Limit | ||||||||||||||||||||||||||||||||||||
| if memoryFactor > 1 { | ||||||||||||||||||||||||||||||||||||
| limit = limit * int64(memoryFactor) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| if limit != 0 && memQuota.Used+memreq > limit { | ||||||||||||||||||||||||||||||||||||
| if memQuota.Used+memreq > limit { | ||||||||||||||||||||||||||||||||||||
| klog.V(4).InfoS("resourceMem quota not fitted", "limit", limit, "used", memQuota.Used, "alloc", memreq) | ||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| coreQuota, ok := (*dq)[coreResourceName] | ||||||||||||||||||||||||||||||||||||
| if ok && coreQuota.Limit != 0 && coreQuota.Used+coresreq > coreQuota.Limit { | ||||||||||||||||||||||||||||||||||||
| if ok && coreQuota.LimitSet && coreQuota.Used+coresreq > coreQuota.Limit { | ||||||||||||||||||||||||||||||||||||
| klog.V(4).InfoS("resourceCores quota not fitted", "limit", coreQuota.Limit, "used", coreQuota.Used, "alloc", coresreq) | ||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -206,6 +207,7 @@ func (q *QuotaManager) AddQuota(quota *corev1.ResourceQuota) { | |||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| (*dp)[dn].Limit = value | ||||||||||||||||||||||||||||||||||||
| (*dp)[dn].LimitSet = true | ||||||||||||||||||||||||||||||||||||
| klog.V(4).InfoS("quota set:", "idx=", idx, "val", value) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -235,6 +237,7 @@ func (q *QuotaManager) DelQuota(quota *corev1.ResourceQuota) { | |||||||||||||||||||||||||||||||||||
| if dq, ok := q.Quotas[quota.Namespace]; ok { | ||||||||||||||||||||||||||||||||||||
| if quotaInfo, ok := (*dq)[dn]; ok { | ||||||||||||||||||||||||||||||||||||
| quotaInfo.Limit = 0 | ||||||||||||||||||||||||||||||||||||
| quotaInfo.LimitSet = false | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -257,8 +260,9 @@ func (q *QuotaManager) GetResourceQuota() map[string]*DeviceQuota { | |||||||||||||||||||||||||||||||||||
| curDQ := &DeviceQuota{} | ||||||||||||||||||||||||||||||||||||
| for name, quota := range *dq { | ||||||||||||||||||||||||||||||||||||
| (*curDQ)[name] = &Quota{ | ||||||||||||||||||||||||||||||||||||
| Used: quota.Used, | ||||||||||||||||||||||||||||||||||||
| Limit: quota.Limit, | ||||||||||||||||||||||||||||||||||||
| Used: quota.Used, | ||||||||||||||||||||||||||||||||||||
| Limit: quota.Limit, | ||||||||||||||||||||||||||||||||||||
| LimitSet: quota.LimitSet, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| quotasCopy[ns] = curDQ | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this changes the prometheus label value from "0" to "unlimited" for namespaces that have usage but no configured quota (LimitSet=false). existing dashboards or alerts that filter on limit="0" for the no-quota case will break silently. the new label is semantically correct, but the change should be called out explicitly for operators.