Skip to content

Commit

Permalink
add report in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuvraj committed Aug 25, 2020
1 parent 513f5ec commit 91c45b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
1 change: 0 additions & 1 deletion cmd/kyverno/main.go
Expand Up @@ -104,7 +104,6 @@ func main() {
setupLog.Error(err, "Failed to create client")
os.Exit(1)
}

// CRD CHECK
// - verify if the CRD for Policy & PolicyViolation are available
if !utils.CRDInstalled(client.DiscoveryClient, log.Log) {
Expand Down
9 changes: 4 additions & 5 deletions pkg/kyverno/apply/command.go
Expand Up @@ -42,13 +42,12 @@ import (
log "sigs.k8s.io/controller-runtime/pkg/log"
)


type resultCounts struct {
pass int
fail int
warn int
pass int
fail int
warn int
error int
skip int
skip int
}

func Command() *cobra.Command {
Expand Down
2 changes: 2 additions & 0 deletions pkg/kyverno/main.go
Expand Up @@ -2,6 +2,7 @@ package kyverno

import (
"flag"
"github.com/nirmata/kyverno/pkg/kyverno/report"
"os"

"github.com/nirmata/kyverno/pkg/kyverno/validate"
Expand All @@ -27,6 +28,7 @@ func CLI() {
commands := []*cobra.Command{
version.Command(),
apply.Command(),
report.Command(),
validate.Command(),
}

Expand Down
32 changes: 16 additions & 16 deletions pkg/policy/validate.go
Expand Up @@ -28,7 +28,7 @@ func Validate(policyRaw []byte, client *dclient.Client, mock bool, openAPIContro
return fmt.Errorf("failed to unmarshal policy admission request err %v", err)
}

if common.PolicyHasVariables(p) && common.PolicyHasNonAllowedVariables(p){
if common.PolicyHasVariables(p) && common.PolicyHasNonAllowedVariables(p) {
return fmt.Errorf("policy contains non allowed variables")
}

Expand All @@ -55,26 +55,26 @@ func Validate(policyRaw []byte, client *dclient.Client, mock bool, openAPIContro
// validate Cluster Resources in namespaced cluster policy
// For namespaced cluster policy, ClusterResource type field and values are not allowed in match and exclude
if !mock && p.ObjectMeta.Namespace != "" {
var Empty struct{}
clusterResourcesMap := make(map[string]*struct{})
// Get all the cluster type kind supported by cluster
res, _ := client.GetDiscoveryCache().ServerPreferredResources()
for _, resList := range res {
for _, r := range resList.APIResources {
if r.Namespaced == false {
if clusterResourcesMap[r.Kind] != nil {
clusterResourcesMap[r.Kind] = &Empty
}
var Empty struct{}
clusterResourcesMap := make(map[string]*struct{})
// Get all the cluster type kind supported by cluster
res, _ := client.GetDiscoveryCache().ServerPreferredResources()
for _, resList := range res {
for _, r := range resList.APIResources {
if r.Namespaced == false {
if clusterResourcesMap[r.Kind] != nil {
clusterResourcesMap[r.Kind] = &Empty
}
}
}
}

clusterResources := make([]string, 0, len(clusterResourcesMap))
for k := range clusterResourcesMap {
clusterResources = append(clusterResources, k)
}
return checkClusterResourceInMatchAndExclude(rule, clusterResources)
clusterResources := make([]string, 0, len(clusterResourcesMap))
for k := range clusterResourcesMap {
clusterResources = append(clusterResources, k)
}
return checkClusterResourceInMatchAndExclude(rule, clusterResources)
}

if doesMatchAndExcludeConflict(rule) {
return fmt.Errorf("path: spec.rules[%v]: rule is matching an empty set", rule.Name)
Expand Down

0 comments on commit 91c45b4

Please sign in to comment.