1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 02:45:06 +00:00

Fix memory issue - RCR conversion (#2678)

This commit is contained in:
shuting 2021-11-08 15:53:21 -08:00 committed by GitHub
parent 0e8341166d
commit 0f0c070072
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 9 deletions

4
go.mod
View file

@ -7,6 +7,7 @@ require (
github.com/cornelk/hashmap v1.0.1
github.com/dchest/siphash v1.2.1 // indirect
github.com/distribution/distribution v2.7.1+incompatible
github.com/docker/cli v20.10.10+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.5.0
github.com/fatih/color v1.12.0
github.com/gardener/controller-manager-library v0.2.0
@ -54,6 +55,9 @@ require (
)
replace (
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017 => github.com/docker/cli v20.10.10+incompatible
github.com/docker/cli v20.10.7+incompatible => github.com/docker/cli v20.10.10+incompatible
github.com/docker/cli v20.10.8+incompatible => github.com/docker/cli v20.10.10+incompatible
github.com/evanphx/json-patch/v5 => github.com/kyverno/json-patch/v5 v5.5.1-0.20210915204938-7578f4ee9c77
github.com/go-logr/logr => github.com/go-logr/logr v0.4.0
github.com/gorilla/rpc v1.2.0+incompatible => github.com/gorilla/rpc v1.2.0

6
go.sum
View file

@ -513,10 +513,8 @@ github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/
github.com/distribution/distribution v2.7.1+incompatible h1:aGFx4EvJWKEh//lHPLwFhFgwFHKH06TzNVPamrMn04M=
github.com/distribution/distribution v2.7.1+incompatible/go.mod h1:EgLm2NgWtdKgzF9NpMzUKgzmR7AMmb0VQi2B+ZzDRjc=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v20.10.7+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v20.10.8+incompatible h1:/zO/6y9IOpcehE49yMRTV9ea0nBpb8OeqSskXLNfH1E=
github.com/docker/cli v20.10.8+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v20.10.10+incompatible h1:kcbwdgWbrBOH8QwQzaJmyriHwF7XIl4HT1qh0HTRys4=
github.com/docker/cli v20.10.10+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY=
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=

View file

@ -1,6 +1,7 @@
package policyreport
import (
"encoding/json"
"fmt"
"reflect"
"time"
@ -17,7 +18,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)
@ -90,6 +91,7 @@ func NewBuilder(cpolLister kyvernolister.ClusterPolicyLister, polLister kyvernol
func (builder *requestBuilder) build(info Info) (req *unstructured.Unstructured, err error) {
results := []*report.PolicyReportResult{}
req = new(unstructured.Unstructured)
for _, infoResult := range info.Results {
for _, rule := range infoResult.Rules {
if rule.Type != utils.Validation.String() {
@ -107,12 +109,19 @@ func (builder *requestBuilder) build(info Info) (req *unstructured.Unstructured,
Results: results,
}
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(rr)
gv := report.SchemeGroupVersion
rr.SetGroupVersionKind(schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: "ReportChangeRequest"})
rawRcr, err := json.Marshal(rr)
if err != nil {
return nil, err
}
err = json.Unmarshal(rawRcr, req)
if err != nil {
return nil, err
}
req = &unstructured.Unstructured{Object: obj}
set(req, info)
} else {
rr := &request.ClusterReportChangeRequest{
@ -120,11 +129,19 @@ func (builder *requestBuilder) build(info Info) (req *unstructured.Unstructured,
Results: results,
}
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(rr)
gv := report.SchemeGroupVersion
rr.SetGroupVersionKind(schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: "ClusterReportChangeRequest"})
rawRcr, err := json.Marshal(rr)
if err != nil {
return nil, err
}
req = &unstructured.Unstructured{Object: obj}
err = json.Unmarshal(rawRcr, req)
if err != nil {
return nil, err
}
set(req, info)
}