From 2eb0e49306559537cd87b8643e43d0ca872fcf26 Mon Sep 17 00:00:00 2001 From: Shuting Zhao Date: Thu, 9 Jan 2020 17:53:27 -0800 Subject: [PATCH] fix build error --- pkg/generate/generate.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/generate/generate.go b/pkg/generate/generate.go index 91ebe7cf43..26c7aa186e 100644 --- a/pkg/generate/generate.go +++ b/pkg/generate/generate.go @@ -1,7 +1,9 @@ package generate import ( + "errors" "fmt" + "reflect" "github.com/golang/glog" kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1" @@ -11,7 +13,7 @@ import ( "github.com/nirmata/kyverno/pkg/engine/validate" "github.com/nirmata/kyverno/pkg/engine/variables" "github.com/nirmata/kyverno/pkg/policyviolation" - "k8s.io/apimachinery/pkg/api/errors" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" ) @@ -240,7 +242,7 @@ func handleData(ruleName string, generateRule kyverno.Generation, client *dclien // check if resource exists obj, err := client.GetResource(generateRule.Kind, generateRule.Namespace, generateRule.Name) glog.V(4).Info(err) - if errors.IsNotFound(err) { + if apierrors.IsNotFound(err) { glog.V(4).Info(string(state)) // Resource does not exist if state == "" { @@ -283,14 +285,14 @@ func handleClone(generateRule kyverno.Generation, client *dclient.Client, resour // resource exists return nil, nil } - if !errors.IsNotFound(err) { + if !apierrors.IsNotFound(err) { //something wrong while fetching resource return nil, err } // get reference clone resource obj, err := client.GetResource(generateRule.Kind, generateRule.Clone.Namespace, generateRule.Clone.Name) - if errors.IsNotFound(err) { + if apierrors.IsNotFound(err) { return nil, NewNotFound(generateRule.Kind, generateRule.Clone.Namespace, generateRule.Clone.Name) } if err != nil { @@ -303,9 +305,9 @@ func handleClone(generateRule kyverno.Generation, client *dclient.Client, resour func checkResource(ctx context.EvalInterface, newResourceSpec interface{}, resource *unstructured.Unstructured) (bool, error) { // check if the resource spec if a subset of the resource path, err := validate.ValidateResourceWithPattern(ctx, resource.Object, newResourceSpec) - if err != nil { + if !reflect.DeepEqual(err, validate.ValidationError{}) { glog.V(4).Infof("config not a subset of resource. failed at path %s: %v", path, err) - return false, err + return false, errors.New(err.ErrorMsg) } return true, nil }