Skip to content

Commit

Permalink
remove namespace check in policy validation
Browse files Browse the repository at this point in the history
  • Loading branch information
realshuting committed Nov 16, 2020
1 parent 9d7c304 commit 63e11c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 1 addition & 3 deletions pkg/policy/generate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func (g *Generate) validateClone(c kyverno.CloneFrom, kind string) (string, erro
if c.Name == "" {
return "name", fmt.Errorf("name cannot be empty")
}
if c.Namespace == "" {
return "namespace", fmt.Errorf("namespace cannot be empty")
}

namespace := c.Namespace
// Skip if there is variable defined
if !variables.IsVariable(kind) && !variables.IsVariable(namespace) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/policyreport/reportcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ func (g *ReportGenerator) syncHandler(key string) error {
func (g *ReportGenerator) createReportIfNotPresent(namespace string, new *unstructured.Unstructured, aggregatedRequests interface{}) (report interface{}, err error) {
log := g.log.WithName("createReportIfNotPresent")
if namespace != "" {
if ns, err := g.nsLister.Get(namespace); err == nil {
if ns.GetDeletionTimestamp() != nil {
return nil, nil
}
}

report, err = g.reportLister.PolicyReports(namespace).Get(generatePolicyReportName((namespace)))
if err != nil {
if apierrors.IsNotFound(err) && new != nil {
Expand Down Expand Up @@ -387,7 +393,9 @@ func (g *ReportGenerator) aggregateReports(namespace string) (
} else {
ns, err := g.nsLister.Get(namespace)
if err != nil {
return nil, nil, fmt.Errorf("unable to get namespace %s: %v", namespace, err)
if !apierrors.IsNotFound(err) {
return nil, nil, fmt.Errorf("unable to get namespace %s: %v", namespace, err)
}
}

selector := labels.SelectorFromSet(labels.Set(map[string]string{"namespace": namespace}))
Expand Down

0 comments on commit 63e11c2

Please sign in to comment.