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

add logging for policy creation and deletion events (#1445)

* add logging for policy creation and deletion events

* update log message

* update log message kind type

Co-authored-by: lengrongfu <lengrongfu@baidu.com>
This commit is contained in:
lengrongfu 2021-01-07 12:34:01 +08:00 committed by GitHub
parent 52d091c5a3
commit fab777cdd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -181,6 +181,9 @@ func (pc *PolicyController) canBackgroundProcess(p *kyverno.ClusterPolicy) bool
func (pc *PolicyController) addPolicy(obj interface{}) {
logger := pc.log
p := obj.(*kyverno.ClusterPolicy)
logger.Info("policy created event", "uid", p.UID, "kind", "ClusterPolicy", "policy_name", p.Name)
if !pc.canBackgroundProcess(p) {
return
}
@ -225,7 +228,7 @@ func (pc *PolicyController) deletePolicy(obj interface{}) {
}
}
logger.V(4).Info("deleting policy", "name", p.Name)
logger.Info("policy deleted event", "uid", p.UID, "kind", "ClusterPolicy", "policy_name", p.Name)
// we process policies that are not set of background processing
// as we need to clean up GRs when a policy is deleted
@ -236,6 +239,9 @@ func (pc *PolicyController) deletePolicy(obj interface{}) {
func (pc *PolicyController) addNsPolicy(obj interface{}) {
logger := pc.log
p := obj.(*kyverno.Policy)
logger.Info("policy created event", "uid", p.UID, "kind", "Policy", "policy_name", p.Name, "namespaces", p.Namespace)
pol := ConvertPolicyToClusterPolicy(p)
if !pc.canBackgroundProcess(pol) {
return
@ -279,8 +285,10 @@ func (pc *PolicyController) deleteNsPolicy(obj interface{}) {
return
}
}
logger.Info("policy deleted event", "uid", p.UID, "kind", "Policy", "policy_name", p.Name, "namespaces", p.Namespace)
pol := ConvertPolicyToClusterPolicy(p)
logger.V(4).Info("deleting namespace policy", "namespace", pol.Namespace, "name", pol.Name)
// we process policies that are not set of background processing
// as we need to clean up GRs when a policy is deleted