mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
pass in patchedResource inside the same mutation rule
This commit is contained in:
parent
b26ed89880
commit
77a6408f30
3 changed files with 5 additions and 2 deletions
|
@ -156,7 +156,7 @@ var podTemplateRule = kyverno.Rule{
|
||||||
"template": map[string]interface{}{
|
"template": map[string]interface{}{
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"annotations": map[string]interface{}{
|
"annotations": map[string]interface{}{
|
||||||
"pod-policies.kyverno.io/autogen-applied": "true",
|
"+(pod-policies.kyverno.io/autogen-applied)": "true",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,11 +25,12 @@ func (ri RuleType) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyPatches patches given resource with given patches and returns patched document
|
// 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) {
|
func ApplyPatches(resource []byte, patches [][]byte) ([]byte, error) {
|
||||||
joinedPatches := JoinPatches(patches)
|
joinedPatches := JoinPatches(patches)
|
||||||
patch, err := jsonpatch.DecodePatch(joinedPatches)
|
patch, err := jsonpatch.DecodePatch(joinedPatches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return resource, err
|
||||||
}
|
}
|
||||||
|
|
||||||
patchedDocument, err := patch.Apply(resource)
|
patchedDocument, err := patch.Apply(resource)
|
||||||
|
|
|
@ -91,6 +91,8 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou
|
||||||
// gather patches
|
// gather patches
|
||||||
patches = append(patches, engineResponse.GetPatches()...)
|
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())
|
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
|
// generate annotations
|
||||||
|
|
Loading…
Add table
Reference in a new issue