1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

skip inserting auto-gen annotation to podController on UPDATE admission request (#953)

This commit is contained in:
shuting 2020-06-25 17:24:10 -07:00 committed by GitHub
parent 1ccd5e6e0f
commit abb51348cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package engine
import (
"encoding/json"
"reflect"
"strings"
"time"
@ -105,6 +106,12 @@ func Mutate(policyContext PolicyContext) (resp response.EngineResponse) {
}
// insert annotation to podtemplate if resource is pod controller
// skip inserting on UPDATE request
if !reflect.DeepEqual(policyContext.OldResource, unstructured.Unstructured{}) {
resp.PatchedResource = patchedResource
return resp
}
// skip inserting on existing resource
if policy.HasAutoGenAnnotation() && strings.Contains(PodControllers, resource.GetKind()) {
if !patchedResourceHasPodControllerAnnotation(patchedResource) {

View file

@ -40,6 +40,11 @@ func (ws *WebhookServer) HandleMutation(
Context: ctx,
}
if request.Operation == v1beta1.Update {
// set OldResource to inform engine of operation type
policyContext.OldResource = resource
}
for _, policy := range policies {
logger.V(3).Info("evaluating policy", "policy", policy.Name)