Skip to content

Commit

Permalink
Reduce RCR throttling requests (kyverno#1376)
Browse files Browse the repository at this point in the history
* reduce RCR throtlling requests

* update logger in init container
  • Loading branch information
realshuting authored Dec 9, 2020
1 parent b7cecd0 commit 39421ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
11 changes: 5 additions & 6 deletions cmd/initContainer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"time"

"github.com/gardener/controller-manager-library/pkg/logger"
"github.com/kyverno/kyverno/pkg/config"
client "github.com/kyverno/kyverno/pkg/dclient"
"github.com/kyverno/kyverno/pkg/signal"
Expand Down Expand Up @@ -321,7 +320,7 @@ func removeReportChangeRequest(client *client.Client, kind string) error {
func removeClusterReportChangeRequest(client *client.Client, kind string) error {
crcrList, err := client.ListResource("", kind, "", nil)
if err != nil && !errors.IsNotFound(err) {
logger.Error(err, "failed to list clusterReportChangeRequest")
log.Log.Error(err, "failed to list clusterReportChangeRequest")
return nil
}

Expand All @@ -334,13 +333,13 @@ func removeClusterReportChangeRequest(client *client.Client, kind string) error
func removeViolationCRD(client *client.Client) error {
if err := client.DeleteResource("", "CustomResourceDefinition", "", "policyviolations.kyverno.io", false); err != nil {
if !errors.IsNotFound(err) {
logger.Error(err, "failed to delete CRD policyViolation")
log.Log.Error(err, "failed to delete CRD policyViolation")
}
}

if err := client.DeleteResource("", "CustomResourceDefinition", "", "clusterpolicyviolations.kyverno.io", false); err != nil {
if !errors.IsNotFound(err) {
logger.Error(err, "failed to delete CRD clusterPolicyViolation")
log.Log.Error(err, "failed to delete CRD clusterPolicyViolation")
}
}
return nil
Expand All @@ -362,9 +361,9 @@ func deleteResource(client *client.Client, apiversion, kind, ns, name string, wg

err := client.DeleteResource(apiversion, kind, ns, name, false)
if err != nil && !errors.IsNotFound(err) {
logger.Error(err, "failed to delete resource", "kind", kind, "name", name)
log.Log.Error(err, "failed to delete resource", "kind", kind, "name", name)
return
}

logger.Info("successfully cleaned up resource", "kind", kind, "name", name)
log.Log.Info("successfully cleaned up resource", "kind", kind, "name", name)
}
15 changes: 4 additions & 11 deletions pkg/policyreport/reportcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"reflect"
"strings"
"sync"

"github.com/go-logr/logr"
changerequest "github.com/kyverno/kyverno/pkg/api/kyverno/v1alpha1"
Expand Down Expand Up @@ -569,19 +568,13 @@ func (g *ReportGenerator) updateReport(old interface{}, new *unstructured.Unstru
func (g *ReportGenerator) cleanupReportRequests(requestsGeneral interface{}) {
defer g.log.V(5).Info("successfully cleaned up report requests")
if requests, ok := requestsGeneral.([]*changerequest.ReportChangeRequest); ok {
var wg sync.WaitGroup
wg.Add(len(requests))
for _, request := range requests {
go func(request *changerequest.ReportChangeRequest) {
if err := g.dclient.DeleteResource(request.APIVersion, "ReportChangeRequest", config.KyvernoNamespace, request.Name, false); err != nil {
if !apierrors.IsNotFound(err) {
g.log.Error(err, "failed to delete report request")
}
if err := g.dclient.DeleteResource(request.APIVersion, "ReportChangeRequest", config.KyvernoNamespace, request.Name, false); err != nil {
if !apierrors.IsNotFound(err) {
g.log.Error(err, "failed to delete report request")
}
wg.Done()
}(request)
}
}
wg.Wait()
}

if requests, ok := requestsGeneral.([]*changerequest.ClusterReportChangeRequest); ok {
Expand Down

0 comments on commit 39421ca

Please sign in to comment.