Skip to content

Commit

Permalink
fix: store policiy and vap in different response fields (#495)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Sep 21, 2023
1 parent 941ef2d commit 3c7648e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/pkg/engine/models/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
"k8s.io/api/admissionregistration/v1alpha1"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -31,10 +32,14 @@ func ConvertResponse(in engineapi.EngineResponse) Response {
out := Response{
OriginalResource: string(resource),
Resource: in.Resource,
Policy: in.Policy().GetPolicy().(kyvernov1.PolicyInterface),
NamespaceLabels: in.NamespaceLabels(),
PatchedResource: string(patchedResource),
}
if in.Policy().GetType() == engineapi.KyvernoPolicyType {
out.Policy = in.Policy().MetaObject().(kyvernov1.PolicyInterface)
} else {
out.ValidatingAdmissionPolicy = in.Policy().MetaObject().(*v1alpha1.ValidatingAdmissionPolicy)
}
for _, ruleresponse := range in.PolicyResponse.Rules {
out.PolicyResponse.Rules = append(out.PolicyResponse.Rules, convertRuleResponse(ruleresponse))
}
Expand Down
3 changes: 3 additions & 0 deletions backend/pkg/engine/models/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"k8s.io/api/admissionregistration/v1alpha1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand All @@ -12,6 +13,8 @@ type Response struct {
Resource unstructured.Unstructured `json:"resource"`
// Policy is the original policy
Policy kyvernov1.PolicyInterface `json:"policy"`
// ValidatingAdmissionPolicy is the original policy
ValidatingAdmissionPolicy *v1alpha1.ValidatingAdmissionPolicy `json:"validatingAdmissionPolicy"`
// namespaceLabels given by policy context
NamespaceLabels map[string]string `json:"namespaceLabels"`
// PatchedResource is the resource patched with the engine action changes
Expand Down

0 comments on commit 3c7648e

Please sign in to comment.