From b7129263c9e3626b8d5bd7c22dea3cf1ebcec859 Mon Sep 17 00:00:00 2001 From: shravan Date: Sun, 26 Jan 2020 19:52:40 +0530 Subject: [PATCH] 536 revised error handling --- pkg/kyverno/apply/command.go | 14 ++++++++++---- pkg/kyverno/validate/command.go | 8 ++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/kyverno/apply/command.go b/pkg/kyverno/apply/command.go index 6cdc35899d..40896242b7 100644 --- a/pkg/kyverno/apply/command.go +++ b/pkg/kyverno/apply/command.go @@ -5,6 +5,8 @@ import ( "fmt" "io/ioutil" + "github.com/golang/glog" + policy2 "github.com/nirmata/kyverno/pkg/policy" "k8s.io/apimachinery/pkg/runtime/schema" @@ -52,20 +54,23 @@ func Command() *cobra.Command { policies, err := getPolicies(policyPaths) if err != nil { - return err + glog.V(4).Infoln(err) + return fmt.Errorf("Issues with policy paths") } var dClient discovery.CachedDiscoveryInterface if cluster { dClient, err = kubernetesConfig.ToDiscoveryClient() if err != nil { - return err + glog.V(4).Infoln(err) + return fmt.Errorf("Issues with kubernetes Config") } } resources, err := getResources(policies, resourcePaths, dClient) if err != nil { - return err + glog.V(4).Infoln(err) + return fmt.Errorf("Issues fetching resources") } for i, policy := range policies { @@ -76,7 +81,8 @@ func Command() *cobra.Command { err = applyPolicyOnResource(policy, resource) if err != nil { - return err + glog.V(4).Infoln(err) + return fmt.Errorf("Issues applying policy %v on resource %v", policy.Name, resource.GetName()) } } } diff --git a/pkg/kyverno/validate/command.go b/pkg/kyverno/validate/command.go index d35da44915..4e4932f370 100644 --- a/pkg/kyverno/validate/command.go +++ b/pkg/kyverno/validate/command.go @@ -5,6 +5,8 @@ import ( "fmt" "io/ioutil" + "github.com/golang/glog" + policyvalidate "github.com/nirmata/kyverno/pkg/policy" v1 "github.com/nirmata/kyverno/pkg/api/kyverno/v1" @@ -27,12 +29,14 @@ func Command() *cobra.Command { for _, policyPath := range policyPaths { policy, err := getPolicy(policyPath) if err != nil { - return err + glog.V(4).Infoln(err) + return fmt.Errorf("Issues with policy path %v", policyPath) } err = policyvalidate.Validate(*policy) if err != nil { - return err + glog.V(4).Infoln(err) + return fmt.Errorf("%v", policyPath) } fmt.Println("Policy " + policy.Name + " is valid")