1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 09:56:55 +00:00
kyverno/pkg/policyreport/mapper.go
shuting 77fb10a430
Clean up RCRs if the count exceeds the threshold (#4148)
* Clean up RCRs if the count exceeds the limit

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* Sets reports to inactive on resourceExhausted error

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* fix linter

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* Add a container flag changeRequestLimit

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* Skip generating RCRs if resourceExhausted error occurs

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* set default RCR limit to 1000

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* Update log messages and CHANGELOG.md

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* Address review comments

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* Extract mapper to a separate file

Signed-off-by: ShutingZhao <shuting@nirmata.com>
2022-06-28 06:18:57 +00:00

24 lines
462 B
Go

package policyreport
import cmap "github.com/orcaman/concurrent-map"
type concurrentMap struct{ cmap.ConcurrentMap }
func (m concurrentMap) increase(ns string) {
count, ok := m.Get(ns)
if ok && count != -1 {
m.Set(ns, count.(int)+1)
} else {
m.Set(ns, 1)
}
}
func (m concurrentMap) decrease(keyHash string) {
_, ns := parseKeyHash(keyHash)
count, ok := m.Get(ns)
if ok && count.(int) > 0 {
m.Set(ns, count.(int)-1)
} else {
m.Set(ns, 0)
}
}