1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

536 revised error handling

This commit is contained in:
shravan 2020-01-26 19:52:40 +05:30
parent 33e55a78e0
commit b7129263c9
2 changed files with 16 additions and 6 deletions

View file

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"github.com/golang/glog"
policy2 "github.com/nirmata/kyverno/pkg/policy" policy2 "github.com/nirmata/kyverno/pkg/policy"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
@ -52,20 +54,23 @@ func Command() *cobra.Command {
policies, err := getPolicies(policyPaths) policies, err := getPolicies(policyPaths)
if err != nil { if err != nil {
return err glog.V(4).Infoln(err)
return fmt.Errorf("Issues with policy paths")
} }
var dClient discovery.CachedDiscoveryInterface var dClient discovery.CachedDiscoveryInterface
if cluster { if cluster {
dClient, err = kubernetesConfig.ToDiscoveryClient() dClient, err = kubernetesConfig.ToDiscoveryClient()
if err != nil { if err != nil {
return err glog.V(4).Infoln(err)
return fmt.Errorf("Issues with kubernetes Config")
} }
} }
resources, err := getResources(policies, resourcePaths, dClient) resources, err := getResources(policies, resourcePaths, dClient)
if err != nil { if err != nil {
return err glog.V(4).Infoln(err)
return fmt.Errorf("Issues fetching resources")
} }
for i, policy := range policies { for i, policy := range policies {
@ -76,7 +81,8 @@ func Command() *cobra.Command {
err = applyPolicyOnResource(policy, resource) err = applyPolicyOnResource(policy, resource)
if err != nil { if err != nil {
return err glog.V(4).Infoln(err)
return fmt.Errorf("Issues applying policy %v on resource %v", policy.Name, resource.GetName())
} }
} }
} }

View file

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"github.com/golang/glog"
policyvalidate "github.com/nirmata/kyverno/pkg/policy" policyvalidate "github.com/nirmata/kyverno/pkg/policy"
v1 "github.com/nirmata/kyverno/pkg/api/kyverno/v1" v1 "github.com/nirmata/kyverno/pkg/api/kyverno/v1"
@ -27,12 +29,14 @@ func Command() *cobra.Command {
for _, policyPath := range policyPaths { for _, policyPath := range policyPaths {
policy, err := getPolicy(policyPath) policy, err := getPolicy(policyPath)
if err != nil { if err != nil {
return err glog.V(4).Infoln(err)
return fmt.Errorf("Issues with policy path %v", policyPath)
} }
err = policyvalidate.Validate(*policy) err = policyvalidate.Validate(*policy)
if err != nil { if err != nil {
return err glog.V(4).Infoln(err)
return fmt.Errorf("%v", policyPath)
} }
fmt.Println("Policy " + policy.Name + " is valid") fmt.Println("Policy " + policy.Name + " is valid")