From 8324949f509c5b4fecc7df3b9a750abf93cfc05d Mon Sep 17 00:00:00 2001 From: shivkumar dudhani Date: Wed, 26 Jun 2019 18:02:01 -0700 Subject: [PATCH] violation struct update --- pkg/apis/policy/v1alpha1/types.go | 11 ++++++----- pkg/violation/builder.go | 11 ++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/apis/policy/v1alpha1/types.go b/pkg/apis/policy/v1alpha1/types.go index 5aac2d1228..dd82165a0c 100644 --- a/pkg/apis/policy/v1alpha1/types.go +++ b/pkg/apis/policy/v1alpha1/types.go @@ -81,11 +81,12 @@ type Status struct { // Violation for the policy type Violation struct { - Kind string `json:"kind,omitempty"` - Resource string `json:"resource,omitempty"` - Rule string `json:"rule,omitempty"` - Reason string `json:"reason,omitempty"` - Message string `json:"message,omitempty"` + Kind string `json:"kind,omitempty"` + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` + Rule string `json:"rule,omitempty"` + Reason string `json:"reason,omitempty"` + Message string `json:"message,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/violation/builder.go b/pkg/violation/builder.go index 32ca2571ec..2b15dd8723 100644 --- a/pkg/violation/builder.go +++ b/pkg/violation/builder.go @@ -64,7 +64,7 @@ func (b *builder) processViolation(info Info) error { newViolation := info.Violation for _, violation := range modifiedPolicy.Status.Violations { - ok, err := b.isActive(info.Kind, violation.Resource) + ok, err := b.isActive(info.Kind, violation.Name) if err != nil { glog.Error(err) continue @@ -102,9 +102,14 @@ func (b *builder) isActive(kind string, resource string) (bool, error) { } //NewViolation return new policy violation -func NewViolation(policyName string, kind string, resource string, rule string) Info { +func NewViolation(policyName string, kind string, rname string, rnamespace string, ruleName string, reason string, msg string) Info { return Info{Policy: policyName, Violation: types.Violation{ - Kind: kind, Resource: resource, Rule: rule}, + Kind: kind, + Name: rname, + Namespace: rnamespace, + Rule: ruleName, + Reason: reason, + }, } }