mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 10:55:05 +00:00
536 revised error handling
This commit is contained in:
parent
33e55a78e0
commit
b7129263c9
2 changed files with 16 additions and 6 deletions
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue