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

replace utilruntime.HandleError with glog.Error

This commit is contained in:
shivdudhani 2019-06-20 11:20:09 -07:00
parent f6ebb056a9
commit 853815720d
5 changed files with 26 additions and 31 deletions

View file

@ -69,7 +69,7 @@ func (pc *PolicyController) deletePolicyHandler(resource interface{}) {
var object metav1.Object
var ok bool
if object, ok = resource.(metav1.Object); !ok {
utilruntime.HandleError(fmt.Errorf("error decoding object, invalid type"))
glog.Error("error decoding object, invalid type")
return
}
glog.Infof("policy deleted: %s", object.GetName())
@ -79,7 +79,7 @@ func (pc *PolicyController) enqueuePolicy(obj interface{}) {
var key string
var err error
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return
}
pc.queue.Add(key)
@ -124,7 +124,7 @@ func (pc *PolicyController) processNextWorkItem() bool {
return nil
}(obj)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return true
}
return true
@ -144,7 +144,7 @@ func (pc *PolicyController) handleErr(err error, key interface{}) {
return
}
pc.queue.Forget(key)
utilruntime.HandleError(err)
glog.Error(err)
glog.Warningf("Dropping the key %q out of the queue: %v", key, err)
}
@ -156,7 +156,7 @@ func (pc *PolicyController) syncHandler(obj interface{}) error {
}
_, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
utilruntime.HandleError(fmt.Errorf("invalid policy key: %s", key))
glog.Errorf("invalid policy key: %s", key)
return nil
}
@ -164,7 +164,7 @@ func (pc *PolicyController) syncHandler(obj interface{}) error {
policy, err := pc.policyLister.Get(name)
if err != nil {
if errors.IsNotFound(err) {
utilruntime.HandleError(fmt.Errorf("policy '%s' in work queue no longer exists", key))
glog.Errorf("policy '%s' in work queue no longer exists", key)
return nil
}
return err

View file

@ -12,7 +12,6 @@ import (
certificates "k8s.io/api/certificates/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/rest"
)
@ -122,7 +121,7 @@ func (c *Client) fetchCertificateFromRequest(req *certificates.CertificateSignin
func (c *Client) ReadRootCASecret() (result []byte) {
certProps, err := c.GetTLSCertProps(c.clientConfig)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return result
}
sname := generateRootCASecretName(certProps)
@ -132,7 +131,7 @@ func (c *Client) ReadRootCASecret() (result []byte) {
}
tlsca, err := convertToSecret(stlsca)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return result
}
@ -164,7 +163,7 @@ func (c *Client) ReadTlsPair(props tls.TlsCertificateProps) *tls.TlsPemPair {
sname := generateRootCASecretName(props)
_, err := c.GetResource(Secrets, props.Namespace, sname)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Root CA secret %s/%s is required while using self-signed certificates TLS pair, defaulting to generating new TLS pair", props.Namespace, sname))
glog.Errorf("Root CA secret %s/%s is required while using self-signed certificates TLS pair, defaulting to generating new TLS pair", props.Namespace, sname)
return nil
}
}

View file

@ -15,7 +15,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory"
"k8s.io/client-go/dynamic"
@ -169,7 +168,7 @@ func (c *Client) UpdateStatusResource(resource string, namespace string, obj int
func convertToUnstructured(obj interface{}) *unstructured.Unstructured {
unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&obj)
if err != nil {
utilruntime.HandleError(fmt.Errorf("Unable to convert : %v", err))
glog.Errorf("Unable to convert : %v", err)
return nil
}
return &unstructured.Unstructured{Object: unstructuredObj}
@ -186,7 +185,7 @@ func (c *Client) GenerateResource(generator types.Generation, namespace string)
if generator.Data != nil {
rdata, err = runtime.DefaultUnstructuredConverter.ToUnstructured(&generator.Data)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return err
}
}
@ -266,12 +265,12 @@ func (c ServerPreferredResources) getGVR(resource string) schema.GroupVersionRes
emptyGVR := schema.GroupVersionResource{}
serverresources, err := c.cachedClient.ServerPreferredResources()
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return emptyGVR
}
resources, err := discovery.GroupVersionResources(serverresources)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return emptyGVR
}
//TODO using cached client to support cache validation and invalidation
@ -290,7 +289,7 @@ func (c ServerPreferredResources) getGVRFromKind(kind string) schema.GroupVersio
emptyGVR := schema.GroupVersionResource{}
serverresources, err := c.cachedClient.ServerPreferredResources()
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return emptyGVR
}
for _, serverresource := range serverresources {
@ -298,7 +297,7 @@ func (c ServerPreferredResources) getGVRFromKind(kind string) schema.GroupVersio
if resource.Kind == kind && !strings.Contains(resource.Name, "/") {
gv, err := schema.ParseGroupVersion(serverresource.GroupVersion)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return emptyGVR
}
return gv.WithResource(resource.Name)

View file

@ -57,14 +57,14 @@ func initRecorder(client *client.Client) record.EventRecorder {
// Initliaze Event Broadcaster
err := policyscheme.AddToScheme(scheme.Scheme)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return nil
}
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
eventInterface, err := client.GetEventsInterface()
if err != nil {
utilruntime.HandleError(err) // TODO: add more specific error
glog.Error(err) // TODO: add more specific error
return nil
}
eventBroadcaster.StartRecordingToSink(
@ -135,13 +135,13 @@ func (c *controller) SyncHandler(key Info) error {
//TODO: policy is clustered resource so wont need namespace
resource, err = c.policyLister.Get(key.Resource)
if err != nil {
utilruntime.HandleError(fmt.Errorf("unable to create event for policy %s, will retry ", key.Resource))
glog.Errorf("unable to create event for policy %s, will retry ", key.Resource)
return err
}
default:
namespace, name, err := cache.SplitMetaNamespaceKey(key.Resource)
if err != nil {
utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", key.Resource))
glog.Errorf("invalid resource key: %s", key.Resource)
return err
}
resource, err = c.client.GetResource(key.Kind, namespace, name)
@ -149,7 +149,7 @@ func (c *controller) SyncHandler(key Info) error {
return err
}
if err != nil {
utilruntime.HandleError(fmt.Errorf("unable to create event for resource %s, will retry ", key.Resource))
glog.Errorf("unable to create event for resource %s, will retry ", key.Resource)
return err
}
}
@ -161,7 +161,7 @@ func (c *controller) SyncHandler(key Info) error {
func NewEvent(kind string, resource string, reason result.Reason, message MsgKey, args ...interface{}) Info {
msgText, err := getEventMsg(message, args)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
}
return Info{
Kind: kind,

View file

@ -1,15 +1,12 @@
package violation
import (
"fmt"
"github.com/golang/glog"
types "github.com/nirmata/kyverno/pkg/apis/policy/v1alpha1"
v1alpha1 "github.com/nirmata/kyverno/pkg/client/listers/policy/v1alpha1"
client "github.com/nirmata/kyverno/pkg/dclient"
event "github.com/nirmata/kyverno/pkg/event"
"github.com/nirmata/kyverno/pkg/sharedinformer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/cache"
)
@ -52,12 +49,12 @@ func (b *builder) processViolation(info Info) error {
// Get the policy
namespace, name, err := cache.SplitMetaNamespaceKey(info.Policy)
if err != nil {
utilruntime.HandleError(fmt.Errorf("unable to extract namespace and name for %s", info.Policy))
glog.Errorf("unable to extract namespace and name for %s", info.Policy)
return err
}
policy, err := b.policyLister.Get(name)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
return err
}
modifiedPolicy := policy.DeepCopy()
@ -69,7 +66,7 @@ func (b *builder) processViolation(info Info) error {
for _, violation := range modifiedPolicy.Status.Violations {
ok, err := b.isActive(info.Kind, violation.Resource)
if err != nil {
utilruntime.HandleError(err)
glog.Error(err)
continue
}
if !ok {
@ -92,13 +89,13 @@ func (b *builder) processViolation(info Info) error {
func (b *builder) isActive(kind string, resource string) (bool, error) {
namespace, name, err := cache.SplitMetaNamespaceKey(resource)
if err != nil {
utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", resource))
glog.Errorf("invalid resource key: %s", resource)
return false, err
}
// Generate Merge Patch
_, err = b.client.GetResource(kind, namespace, name)
if err != nil {
utilruntime.HandleError(fmt.Errorf("unable to get resource %s ", resource))
glog.Errorf("unable to get resource %s ", resource)
return false, err
}
return true, nil