1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 10:55:05 +00:00

pass in patchedResource inside the same mutation rule

This commit is contained in:
Shuting Zhao 2020-01-15 18:15:48 -08:00
parent b26ed89880
commit 77a6408f30
3 changed files with 5 additions and 2 deletions

View file

@ -156,7 +156,7 @@ var podTemplateRule = kyverno.Rule{
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"pod-policies.kyverno.io/autogen-applied": "true",
"+(pod-policies.kyverno.io/autogen-applied)": "true",
},
},
},

View file

@ -25,11 +25,12 @@ func (ri RuleType) String() string {
}
// ApplyPatches patches given resource with given patches and returns patched document
// return origin resource if any error occurs
func ApplyPatches(resource []byte, patches [][]byte) ([]byte, error) {
joinedPatches := JoinPatches(patches)
patch, err := jsonpatch.DecodePatch(joinedPatches)
if err != nil {
return nil, err
return resource, err
}
patchedDocument, err := patch.Apply(resource)

View file

@ -91,6 +91,8 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou
// gather patches
patches = append(patches, engineResponse.GetPatches()...)
glog.V(4).Infof("Mutation from policy %s has applied succesfully to %s %s/%s", policy.Name, request.Kind.Kind, resource.GetNamespace(), resource.GetName())
policyContext.NewResource = engineResponse.PatchedResource
}
// generate annotations