mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
Fix memory leak - remove item from the cache once done (audit handler) (#1459)
* remove entry from audit handler * fix test
This commit is contained in:
parent
ff246a81a1
commit
e7a04b9138
2 changed files with 18 additions and 3 deletions
|
@ -15,7 +15,7 @@ func TestExpandInMetadata(t *testing.T) {
|
|||
testExpand(t, map[string]string{"=(test/*)": "test"}, map[string]string{"test/test": "test"},
|
||||
map[string]interface{}{"=(test/test)": "test"})
|
||||
|
||||
testExpand(t, map[string]string{"test/*": "*"}, map[string]string{"test/test1": "test1", "test/test2": "test2"},
|
||||
testExpand(t, map[string]string{"test/*": "*"}, map[string]string{"test/test1": "test1"},
|
||||
map[string]interface{}{"test/test1": "*"})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package webhooks
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
|
@ -129,7 +130,7 @@ func (h *auditHandler) processNextWorkItem() bool {
|
|||
}
|
||||
|
||||
err := h.process(request)
|
||||
h.handleErr(err)
|
||||
h.handleErr(err, obj, request)
|
||||
|
||||
return true
|
||||
}
|
||||
|
@ -176,6 +177,20 @@ func (h *auditHandler) process(request *v1beta1.AdmissionRequest) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *auditHandler) handleErr(err error) {
|
||||
func (h *auditHandler) handleErr(err error, key interface{}, request *v1beta1.AdmissionRequest) {
|
||||
logger := h.log.WithName("handleErr")
|
||||
if err == nil {
|
||||
h.queue.Forget(key)
|
||||
return
|
||||
}
|
||||
|
||||
k := strings.Join([]string{request.Kind.Kind, request.Namespace, request.Name}, "/")
|
||||
if h.queue.NumRequeues(key) < workQueueRetryLimit {
|
||||
logger.V(3).Info("retrying processing admission request", "key", k, "error", err.Error())
|
||||
h.queue.AddRateLimited(key)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Error(err, "failed to process admission request", "key", k)
|
||||
h.queue.Forget(key)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue