From d9c3a166ccec3864a54ec1d0a1d030c62b4e9adb Mon Sep 17 00:00:00 2001 From: NoSkillGirl Date: Mon, 31 Aug 2020 19:32:00 +0530 Subject: [PATCH] updated readme --- documentation/kyverno-cli.md | 6 ++++++ pkg/kyverno/common/common.go | 6 ++++-- pkg/kyverno/validate/command.go | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/documentation/kyverno-cli.md b/documentation/kyverno-cli.md index 44ebe3e136..22995f4a44 100644 --- a/documentation/kyverno-cli.md +++ b/documentation/kyverno-cli.md @@ -61,6 +61,12 @@ Example: kyverno validate /path/to/policy1.yaml /path/to/policy2.yaml /path/to/folderFullOfPolicies -o yaml ``` +Policy can also be validated with CRDs. Use -c flag to pass the CRD, can pass multiple CRD files or even an entire folder containin CRDs. + +Example: +``` +kyverno validate /path/to/policy1.yaml -c /path/to/crd.yaml -c /path/to/folderFullOfCRDs +``` #### Apply Applies policies on resources, and supports applying multiple policies on multiple resources in a single command. diff --git a/pkg/kyverno/common/common.go b/pkg/kyverno/common/common.go index b7a70e88fb..62153fc296 100644 --- a/pkg/kyverno/common/common.go +++ b/pkg/kyverno/common/common.go @@ -7,13 +7,14 @@ import ( "fmt" "io" "io/ioutil" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "os" "path/filepath" "regexp" - yaml_v2 "sigs.k8s.io/yaml" "strings" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + yaml_v2 "sigs.k8s.io/yaml" + jsonpatch "github.com/evanphx/json-patch" "github.com/go-logr/logr" v1 "github.com/nirmata/kyverno/pkg/api/kyverno/v1" @@ -249,6 +250,7 @@ func GetCRDs(paths []string) (unstructuredCrds []*unstructured.Unstructured, err getCRDs, err := GetCRD(path) if err != nil { fmt.Printf("failed to extract crds: %s\n", err) + os.Exit(2) } unstructuredCrds = append(unstructuredCrds, getCRDs...) } diff --git a/pkg/kyverno/validate/command.go b/pkg/kyverno/validate/command.go index aa47ed2878..f32cf2dc24 100644 --- a/pkg/kyverno/validate/command.go +++ b/pkg/kyverno/validate/command.go @@ -56,6 +56,7 @@ func Command() *cobra.Command { if err != nil { log.Error(err, "crd is invalid", "file", crdPaths) + os.Exit(1) } for _, crd := range crds { openAPIController.ParseCRD(*crd)